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#include <linux/kernel.h>
34#include <linux/version.h>
35#include <linux/module.h>
36#include <linux/pci.h>
37#include <linux/slab.h>
38
39#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
40#include <linux/sched.h>
41#endif
42
43#include "dgnc_driver.h"
44#include "dgnc_pci.h"
45#include "dpacompat.h"
46#include "dgnc_mgmt.h"
47#include "dgnc_tty.h"
48#include "dgnc_trace.h"
49#include "dgnc_cls.h"
50#include "dgnc_neo.h"
51#include "dgnc_sysfs.h"
52
53MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Digi International, http://www.digi.com");
55MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
56MODULE_SUPPORTED_DEVICE("dgnc");
57
58
59
60
61
62
63
64PARM_INT(debug, 0x00, 0644, "Driver debugging level");
65PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
66PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
67
68
69
70
71
72
73static int dgnc_start(void);
74static int dgnc_finalize_board_init(struct board_t *brd);
75static void dgnc_init_globals(void);
76static int dgnc_found_board(struct pci_dev *pdev, int id);
77static void dgnc_cleanup_board(struct board_t *brd);
78static void dgnc_poll_handler(ulong dummy);
79static int dgnc_init_pci(void);
80static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
81static void dgnc_remove_one(struct pci_dev *dev);
82static int dgnc_probe1(struct pci_dev *pdev, int card_type);
83static void dgnc_do_remap(struct board_t *brd);
84
85
86int dgnc_init_module(void);
87void dgnc_cleanup_module(void);
88
89module_init(dgnc_init_module);
90module_exit(dgnc_cleanup_module);
91
92
93
94
95
96static struct file_operations dgnc_BoardFops =
97{
98 .owner = THIS_MODULE,
99 .unlocked_ioctl = dgnc_mgmt_ioctl,
100 .open = dgnc_mgmt_open,
101 .release = dgnc_mgmt_close
102};
103
104
105
106
107
108uint dgnc_NumBoards;
109struct board_t *dgnc_Board[MAXBOARDS];
110DEFINE_SPINLOCK(dgnc_global_lock);
111int dgnc_driver_state = DRIVER_INITIALIZED;
112ulong dgnc_poll_counter;
113uint dgnc_Major;
114int dgnc_poll_tick = 20;
115
116
117
118
119static uint dgnc_Major_Control_Registered = FALSE;
120static uint dgnc_driver_start = FALSE;
121
122static struct class *dgnc_class;
123
124
125
126
127static DEFINE_SPINLOCK(dgnc_poll_lock);
128static ulong dgnc_poll_time;
129static uint dgnc_poll_stop;
130static struct timer_list dgnc_poll_timer;
131
132
133static struct pci_device_id dgnc_pci_tbl[] = {
134 { DIGI_VID, PCI_DEVICE_CLASSIC_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
135 { DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
136 { DIGI_VID, PCI_DEVICE_CLASSIC_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
137 { DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
138 { DIGI_VID, PCI_DEVICE_NEO_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
139 { DIGI_VID, PCI_DEVICE_NEO_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
140 { DIGI_VID, PCI_DEVICE_NEO_2DB9_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
141 { DIGI_VID, PCI_DEVICE_NEO_2DB9PRI_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
142 { DIGI_VID, PCI_DEVICE_NEO_2RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
143 { DIGI_VID, PCI_DEVICE_NEO_2RJ45PRI_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
144 { DIGI_VID, PCI_DEVICE_NEO_1_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
145 { DIGI_VID, PCI_DEVICE_NEO_1_422_485_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
146 { DIGI_VID, PCI_DEVICE_NEO_2_422_485_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
147 { DIGI_VID, PCI_DEVICE_NEO_EXPRESS_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
148 { DIGI_VID, PCI_DEVICE_NEO_EXPRESS_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
149 { DIGI_VID, PCI_DEVICE_NEO_EXPRESS_4RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 15 },
150 { DIGI_VID, PCI_DEVICE_NEO_EXPRESS_8RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 16 },
151 {0,}
152};
153MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);
154
155struct board_id {
156 uchar *name;
157 uint maxports;
158 unsigned int is_pci_express;
159};
160
161static struct board_id dgnc_Ids[] =
162{
163 { PCI_DEVICE_CLASSIC_4_PCI_NAME, 4, 0 },
164 { PCI_DEVICE_CLASSIC_4_422_PCI_NAME, 4, 0 },
165 { PCI_DEVICE_CLASSIC_8_PCI_NAME, 8, 0 },
166 { PCI_DEVICE_CLASSIC_8_422_PCI_NAME, 8, 0 },
167 { PCI_DEVICE_NEO_4_PCI_NAME, 4, 0 },
168 { PCI_DEVICE_NEO_8_PCI_NAME, 8, 0 },
169 { PCI_DEVICE_NEO_2DB9_PCI_NAME, 2, 0 },
170 { PCI_DEVICE_NEO_2DB9PRI_PCI_NAME, 2, 0 },
171 { PCI_DEVICE_NEO_2RJ45_PCI_NAME, 2, 0 },
172 { PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME, 2, 0 },
173 { PCI_DEVICE_NEO_1_422_PCI_NAME, 1, 0 },
174 { PCI_DEVICE_NEO_1_422_485_PCI_NAME, 1, 0 },
175 { PCI_DEVICE_NEO_2_422_485_PCI_NAME, 2, 0 },
176 { PCI_DEVICE_NEO_EXPRESS_8_PCI_NAME, 8, 1 },
177 { PCI_DEVICE_NEO_EXPRESS_4_PCI_NAME, 4, 1 },
178 { PCI_DEVICE_NEO_EXPRESS_4RJ45_PCI_NAME, 4, 1 },
179 { PCI_DEVICE_NEO_EXPRESS_8RJ45_PCI_NAME, 8, 1 },
180 { NULL, 0, 0 }
181};
182
183static struct pci_driver dgnc_driver = {
184 .name = "dgnc",
185 .probe = dgnc_init_one,
186 .id_table = dgnc_pci_tbl,
187 .remove = dgnc_remove_one,
188};
189
190
191char *dgnc_state_text[] = {
192 "Board Failed",
193 "Board Found",
194 "Board READY",
195};
196
197char *dgnc_driver_state_text[] = {
198 "Driver Initialized",
199 "Driver Ready."
200};
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216int dgnc_init_module(void)
217{
218 int rc = 0;
219
220 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
221
222
223
224
225 rc = dgnc_start();
226
227 if (rc < 0) {
228 return(rc);
229 }
230
231
232
233
234 rc = dgnc_init_pci();
235
236
237
238
239 if (rc < 0) {
240
241 if (dgnc_NumBoards)
242 pci_unregister_driver(&dgnc_driver);
243 else
244 printk("WARNING: dgnc driver load failed. No Digi Neo or Classic boards found.\n");
245
246 dgnc_cleanup_module();
247 }
248 else {
249 dgnc_create_driver_sysfiles(&dgnc_driver);
250 }
251
252 DPR_INIT(("Finished init_module. Returning %d\n", rc));
253 return (rc);
254}
255
256
257
258
259
260static int dgnc_start(void)
261{
262 int rc = 0;
263 unsigned long flags;
264
265 if (dgnc_driver_start == FALSE) {
266
267 dgnc_driver_start = TRUE;
268
269
270 dgnc_init_globals();
271
272 dgnc_NumBoards = 0;
273
274 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
275
276
277
278
279
280
281 if (!dgnc_Major_Control_Registered) {
282
283
284
285 rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
286 if (rc <= 0) {
287 APR(("Can't register dgnc driver device (%d)\n", rc));
288 rc = -ENXIO;
289 return(rc);
290 }
291 dgnc_Major = rc;
292
293 dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
294#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
295 device_create_drvdata(dgnc_class, NULL,
296 MKDEV(dgnc_Major, 0),
297 NULL, "dgnc_mgmt");
298#else
299 device_create(dgnc_class, NULL,
300 MKDEV(dgnc_Major, 0),
301 NULL, "dgnc_mgmt");
302#endif
303
304 dgnc_Major_Control_Registered = TRUE;
305 }
306
307
308
309
310 rc = dgnc_tty_preinit();
311
312 if (rc < 0) {
313 APR(("tty preinit - not enough memory (%d)\n", rc));
314 return(rc);
315 }
316
317
318 DGNC_LOCK(dgnc_poll_lock, flags);
319 init_timer(&dgnc_poll_timer);
320 dgnc_poll_timer.function = dgnc_poll_handler;
321 dgnc_poll_timer.data = 0;
322 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
323 dgnc_poll_timer.expires = dgnc_poll_time;
324 DGNC_UNLOCK(dgnc_poll_lock, flags);
325
326 add_timer(&dgnc_poll_timer);
327
328 dgnc_driver_state = DRIVER_READY;
329 }
330
331 return(rc);
332}
333
334
335
336
337static int dgnc_init_pci(void)
338{
339 return pci_register_driver(&dgnc_driver);
340}
341
342
343
344static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
345{
346 int rc;
347
348
349 rc = pci_enable_device(pdev);
350
351 if (rc < 0) {
352 rc = -EIO;
353 } else {
354 rc = dgnc_probe1(pdev, ent->driver_data);
355 if (rc == 0) {
356 dgnc_NumBoards++;
357 DPR_INIT(("Incrementing numboards to %d\n", dgnc_NumBoards));
358 }
359 }
360 return rc;
361}
362
363static int dgnc_probe1(struct pci_dev *pdev, int card_type)
364{
365 return dgnc_found_board(pdev, card_type);
366}
367
368
369static void dgnc_remove_one(struct pci_dev *dev)
370{
371
372}
373
374
375
376
377
378
379void dgnc_cleanup_module(void)
380{
381 int i;
382 ulong lock_flags;
383
384 DGNC_LOCK(dgnc_poll_lock, lock_flags);
385 dgnc_poll_stop = 1;
386 DGNC_UNLOCK(dgnc_poll_lock, lock_flags);
387
388
389 del_timer_sync(&dgnc_poll_timer);
390
391 dgnc_remove_driver_sysfiles(&dgnc_driver);
392
393 if (dgnc_Major_Control_Registered) {
394 device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
395 class_destroy(dgnc_class);
396 unregister_chrdev(dgnc_Major, "dgnc");
397 }
398
399 for (i = 0; i < dgnc_NumBoards; ++i) {
400 dgnc_remove_ports_sysfiles(dgnc_Board[i]);
401 dgnc_tty_uninit(dgnc_Board[i]);
402 dgnc_cleanup_board(dgnc_Board[i]);
403 }
404
405 dgnc_tty_post_uninit();
406
407#if defined(DGNC_TRACER)
408
409 dgnc_tracer_free();
410#endif
411 if (dgnc_NumBoards)
412 pci_unregister_driver(&dgnc_driver);
413}
414
415
416
417
418
419
420
421static void dgnc_cleanup_board(struct board_t *brd)
422{
423 int i = 0;
424
425 if(!brd || brd->magic != DGNC_BOARD_MAGIC)
426 return;
427
428 switch (brd->device) {
429 case PCI_DEVICE_CLASSIC_4_DID:
430 case PCI_DEVICE_CLASSIC_8_DID:
431 case PCI_DEVICE_CLASSIC_4_422_DID:
432 case PCI_DEVICE_CLASSIC_8_422_DID:
433
434
435 outb(0, brd->iobase + 0x4c);
436 break;
437
438 default:
439 break;
440 }
441
442 if (brd->irq)
443 free_irq(brd->irq, brd);
444
445 tasklet_kill(&brd->helper_tasklet);
446
447 if (brd->re_map_membase) {
448 iounmap(brd->re_map_membase);
449 brd->re_map_membase = NULL;
450 }
451
452 if (brd->msgbuf_head) {
453 unsigned long flags;
454
455 DGNC_LOCK(dgnc_global_lock, flags);
456 brd->msgbuf = NULL;
457 printk("%s", brd->msgbuf_head);
458 kfree(brd->msgbuf_head);
459 brd->msgbuf_head = NULL;
460 DGNC_UNLOCK(dgnc_global_lock, flags);
461 }
462
463
464 for (i = 0; i < MAXPORTS ; i++) {
465 if (brd->channels[i]) {
466 if (brd->channels[i]->ch_rqueue)
467 kfree(brd->channels[i]->ch_rqueue);
468 if (brd->channels[i]->ch_equeue)
469 kfree(brd->channels[i]->ch_equeue);
470 if (brd->channels[i]->ch_wqueue)
471 kfree(brd->channels[i]->ch_wqueue);
472
473 kfree(brd->channels[i]);
474 brd->channels[i] = NULL;
475 }
476 }
477
478 if (brd->flipbuf)
479 kfree(brd->flipbuf);
480
481 dgnc_Board[brd->boardnum] = NULL;
482
483 kfree(brd);
484}
485
486
487
488
489
490
491
492static int dgnc_found_board(struct pci_dev *pdev, int id)
493{
494 struct board_t *brd;
495 unsigned int pci_irq;
496 int i = 0;
497 int rc = 0;
498 unsigned long flags;
499
500
501 brd = dgnc_Board[dgnc_NumBoards] =
502 (struct board_t *) kzalloc(sizeof(struct board_t), GFP_KERNEL);
503 if (!brd) {
504 APR(("memory allocation for board structure failed\n"));
505 return(-ENOMEM);
506 }
507
508
509 brd->msgbuf = brd->msgbuf_head =
510 (char *) kzalloc(sizeof(char) * 8192, GFP_KERNEL);
511 if (!brd->msgbuf) {
512 kfree(brd);
513 APR(("memory allocation for board msgbuf failed\n"));
514 return(-ENOMEM);
515 }
516
517
518 brd->magic = DGNC_BOARD_MAGIC;
519 brd->boardnum = dgnc_NumBoards;
520 brd->vendor = dgnc_pci_tbl[id].vendor;
521 brd->device = dgnc_pci_tbl[id].device;
522 brd->pdev = pdev;
523 brd->pci_bus = pdev->bus->number;
524 brd->pci_slot = PCI_SLOT(pdev->devfn);
525 brd->name = dgnc_Ids[id].name;
526 brd->maxports = dgnc_Ids[id].maxports;
527 if (dgnc_Ids[i].is_pci_express)
528 brd->bd_flags |= BD_IS_PCI_EXPRESS;
529 brd->dpastatus = BD_NOFEP;
530 init_waitqueue_head(&brd->state_wait);
531
532 DGNC_SPINLOCK_INIT(brd->bd_lock);
533 DGNC_SPINLOCK_INIT(brd->bd_intr_lock);
534
535 brd->state = BOARD_FOUND;
536
537 for (i = 0; i < MAXPORTS; i++) {
538 brd->channels[i] = NULL;
539 }
540
541
542 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
543 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
544 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
545
546 pci_irq = pdev->irq;
547 brd->irq = pci_irq;
548
549
550 switch(brd->device) {
551
552 case PCI_DEVICE_CLASSIC_4_DID:
553 case PCI_DEVICE_CLASSIC_8_DID:
554 case PCI_DEVICE_CLASSIC_4_422_DID:
555 case PCI_DEVICE_CLASSIC_8_422_DID:
556
557 brd->dpatype = T_CLASSIC | T_PCIBUS;
558
559 DPR_INIT(("dgnc_found_board - Classic.\n"));
560
561
562
563
564
565
566
567
568
569
570
571
572
573 brd->membase = pci_resource_start(pdev, 4);
574
575 if (!brd->membase) {
576 APR(("card has no PCI IO resources, failing board.\n"));
577 return -ENODEV;
578 }
579
580 brd->membase_end = pci_resource_end(pdev, 4);
581
582 if (brd->membase & 1)
583 brd->membase &= ~3;
584 else
585 brd->membase &= ~15;
586
587 brd->iobase = pci_resource_start(pdev, 1);
588 brd->iobase_end = pci_resource_end(pdev, 1);
589 brd->iobase = ((unsigned int) (brd->iobase)) & 0xFFFE;
590
591
592 brd->bd_ops = &dgnc_cls_ops;
593
594 brd->bd_uart_offset = 0x8;
595 brd->bd_dividend = 921600;
596
597 dgnc_do_remap(brd);
598
599
600 brd->bd_ops->vpd(brd);
601
602
603
604
605
606
607 outb(0x43, brd->iobase + 0x4c);
608
609 break;
610
611
612 case PCI_DEVICE_NEO_4_DID:
613 case PCI_DEVICE_NEO_8_DID:
614 case PCI_DEVICE_NEO_2DB9_DID:
615 case PCI_DEVICE_NEO_2DB9PRI_DID:
616 case PCI_DEVICE_NEO_2RJ45_DID:
617 case PCI_DEVICE_NEO_2RJ45PRI_DID:
618 case PCI_DEVICE_NEO_1_422_DID:
619 case PCI_DEVICE_NEO_1_422_485_DID:
620 case PCI_DEVICE_NEO_2_422_485_DID:
621 case PCI_DEVICE_NEO_EXPRESS_8_DID:
622 case PCI_DEVICE_NEO_EXPRESS_4_DID:
623 case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
624 case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
625
626
627
628
629
630 if (brd->bd_flags & BD_IS_PCI_EXPRESS)
631 brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
632 else
633 brd->dpatype = T_NEO | T_PCIBUS;
634
635 DPR_INIT(("dgnc_found_board - NEO.\n"));
636
637
638 brd->membase = pci_resource_start(pdev, 0);
639 brd->membase_end = pci_resource_end(pdev, 0);
640
641 if (brd->membase & 1)
642 brd->membase &= ~3;
643 else
644 brd->membase &= ~15;
645
646
647 brd->bd_ops = &dgnc_neo_ops;
648
649 brd->bd_uart_offset = 0x200;
650 brd->bd_dividend = 921600;
651
652 dgnc_do_remap(brd);
653
654 if (brd->re_map_membase) {
655
656
657 brd->dvid = readb(brd->re_map_membase + 0x8D);
658
659
660 brd->bd_ops->vpd(brd);
661 }
662 break;
663
664 default:
665 APR(("Did not find any compatible Neo or Classic PCI boards in system.\n"));
666 return (-ENXIO);
667
668 }
669
670
671
672
673
674 rc = dgnc_tty_register(brd);
675 if (rc < 0) {
676 dgnc_tty_uninit(brd);
677 APR(("Can't register tty devices (%d)\n", rc));
678 brd->state = BOARD_FAILED;
679 brd->dpastatus = BD_NOFEP;
680 goto failed;
681 }
682
683 rc = dgnc_finalize_board_init(brd);
684 if (rc < 0) {
685 APR(("Can't finalize board init (%d)\n", rc));
686 brd->state = BOARD_FAILED;
687 brd->dpastatus = BD_NOFEP;
688
689 goto failed;
690 }
691
692 rc = dgnc_tty_init(brd);
693 if (rc < 0) {
694 dgnc_tty_uninit(brd);
695 APR(("Can't init tty devices (%d)\n", rc));
696 brd->state = BOARD_FAILED;
697 brd->dpastatus = BD_NOFEP;
698
699 goto failed;
700 }
701
702 brd->state = BOARD_READY;
703 brd->dpastatus = BD_RUNNING;
704
705 dgnc_create_ports_sysfiles(brd);
706
707
708 tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, (unsigned long) brd);
709
710 DPR_INIT(("dgnc_scan(%d) - printing out the msgbuf\n", i));
711 DGNC_LOCK(dgnc_global_lock, flags);
712 brd->msgbuf = NULL;
713 printk("%s", brd->msgbuf_head);
714 kfree(brd->msgbuf_head);
715 brd->msgbuf_head = NULL;
716 DGNC_UNLOCK(dgnc_global_lock, flags);
717
718
719
720
721
722
723
724 brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
725
726 wake_up_interruptible(&brd->state_wait);
727
728 return(0);
729
730failed:
731
732 return (-ENXIO);
733
734}
735
736
737static int dgnc_finalize_board_init(struct board_t *brd) {
738 int rc = 0;
739
740 DPR_INIT(("dgnc_finalize_board_init() - start\n"));
741
742 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
743 return(-ENODEV);
744
745 DPR_INIT(("dgnc_finalize_board_init() - start #2\n"));
746
747 if (brd->irq) {
748 rc = request_irq(brd->irq, brd->bd_ops->intr, IRQF_SHARED, "DGNC", brd);
749
750 if (rc) {
751 printk("Failed to hook IRQ %d\n",brd->irq);
752 brd->state = BOARD_FAILED;
753 brd->dpastatus = BD_NOFEP;
754 rc = -ENODEV;
755 } else {
756 DPR_INIT(("Requested and received usage of IRQ %d\n", brd->irq));
757 }
758 }
759 return(rc);
760}
761
762
763
764
765static void dgnc_do_remap(struct board_t *brd)
766{
767
768 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
769 return;
770
771 brd->re_map_membase = ioremap(brd->membase, 0x1000);
772
773 DPR_INIT(("remapped mem: 0x%p\n", brd->re_map_membase));
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
803static void dgnc_poll_handler(ulong dummy)
804{
805 struct board_t *brd;
806 unsigned long lock_flags;
807 int i;
808 unsigned long new_time;
809
810 dgnc_poll_counter++;
811
812
813
814
815
816
817 if (dgnc_driver_state != DRIVER_READY) {
818 goto schedule_poller;
819 }
820
821
822 for (i = 0; i < dgnc_NumBoards; i++) {
823 brd = dgnc_Board[i];
824
825 DGNC_LOCK(brd->bd_lock, lock_flags);
826
827
828 if (brd->state == BOARD_FAILED) {
829 DGNC_UNLOCK(brd->bd_lock, lock_flags);
830 continue;
831 }
832
833
834 tasklet_schedule(&brd->helper_tasklet);
835
836 DGNC_UNLOCK(brd->bd_lock, lock_flags);
837 }
838
839schedule_poller:
840
841
842
843
844 DGNC_LOCK(dgnc_poll_lock, lock_flags);
845 dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
846
847 new_time = dgnc_poll_time - jiffies;
848
849 if ((ulong) new_time >= 2 * dgnc_poll_tick) {
850 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
851 }
852
853 init_timer(&dgnc_poll_timer);
854 dgnc_poll_timer.function = dgnc_poll_handler;
855 dgnc_poll_timer.data = 0;
856 dgnc_poll_timer.expires = dgnc_poll_time;
857 DGNC_UNLOCK(dgnc_poll_lock, lock_flags);
858
859 if (!dgnc_poll_stop)
860 add_timer(&dgnc_poll_timer);
861}
862
863
864
865
866
867
868
869
870static void dgnc_init_globals(void)
871{
872 int i = 0;
873
874 dgnc_rawreadok = rawreadok;
875 dgnc_trcbuf_size = trcbuf_size;
876 dgnc_debug = debug;
877
878 for (i = 0; i < MAXBOARDS; i++) {
879 dgnc_Board[i] = NULL;
880 }
881
882 init_timer(&dgnc_poll_timer);
883}
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899int dgnc_ms_sleep(ulong ms)
900{
901 current->state = TASK_INTERRUPTIBLE;
902 schedule_timeout((ms * HZ) / 1000);
903 return (signal_pending(current));
904}
905
906
907
908
909
910
911char *dgnc_ioctl_name(int cmd)
912{
913 switch(cmd) {
914
915 case TCGETA: return("TCGETA");
916 case TCGETS: return("TCGETS");
917 case TCSETA: return("TCSETA");
918 case TCSETS: return("TCSETS");
919 case TCSETAW: return("TCSETAW");
920 case TCSETSW: return("TCSETSW");
921 case TCSETAF: return("TCSETAF");
922 case TCSETSF: return("TCSETSF");
923 case TCSBRK: return("TCSBRK");
924 case TCXONC: return("TCXONC");
925 case TCFLSH: return("TCFLSH");
926 case TIOCGSID: return("TIOCGSID");
927
928 case TIOCGETD: return("TIOCGETD");
929 case TIOCSETD: return("TIOCSETD");
930 case TIOCGWINSZ: return("TIOCGWINSZ");
931 case TIOCSWINSZ: return("TIOCSWINSZ");
932
933 case TIOCMGET: return("TIOCMGET");
934 case TIOCMSET: return("TIOCMSET");
935 case TIOCMBIS: return("TIOCMBIS");
936 case TIOCMBIC: return("TIOCMBIC");
937
938
939 case DIGI_SETA: return("DIGI_SETA");
940 case DIGI_SETAW: return("DIGI_SETAW");
941 case DIGI_SETAF: return("DIGI_SETAF");
942 case DIGI_SETFLOW: return("DIGI_SETFLOW");
943 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
944 case DIGI_GETFLOW: return("DIGI_GETFLOW");
945 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
946 case DIGI_GETA: return("DIGI_GETA");
947 case DIGI_GEDELAY: return("DIGI_GEDELAY");
948 case DIGI_SEDELAY: return("DIGI_SEDELAY");
949 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
950 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
951 case TIOCMODG: return("TIOCMODG");
952 case TIOCMODS: return("TIOCMODS");
953 case TIOCSDTR: return("TIOCSDTR");
954 case TIOCCDTR: return("TIOCCDTR");
955
956 default: return("unknown");
957 }
958}
959