Merge tag 'please-pull-einj-mmcfg' of git://git.kernel.org/pub/scm/linux/kernel/git...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / dgnc / dgnc_driver.c
1 /*
2  * Copyright 2003 Digi International (www.digi.com)
3  *      Scott H Kilau <Scott_Kilau at digi dot com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  * PURPOSE.  See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *
20  *      NOTE TO LINUX KERNEL HACKERS:  DO NOT REFORMAT THIS CODE!
21  *
22  *      This is shared code between Digi's CVS archive and the
23  *      Linux Kernel sources.
24  *      Changing the source just for reformatting needlessly breaks
25  *      our CVS diff history.
26  *
27  *      Send any bug fixes/changes to:  Eng.Linux at digi dot com.
28  *      Thank you.
29  *
30  */
31
32
33 #include <linux/kernel.h>
34 #include <linux/module.h>
35 #include <linux/pci.h>
36 #include <linux/slab.h>
37 #include <linux/sched.h>
38 #include "dgnc_driver.h"
39 #include "dgnc_pci.h"
40 #include "dpacompat.h"
41 #include "dgnc_mgmt.h"
42 #include "dgnc_tty.h"
43 #include "dgnc_cls.h"
44 #include "dgnc_neo.h"
45 #include "dgnc_sysfs.h"
46
47 MODULE_LICENSE("GPL");
48 MODULE_AUTHOR("Digi International, http://www.digi.com");
49 MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
50 MODULE_SUPPORTED_DEVICE("dgnc");
51
52 /**************************************************************************
53  *
54  * protos for this file
55  *
56  */
57 static int              dgnc_start(void);
58 static int              dgnc_finalize_board_init(struct dgnc_board *brd);
59 static void             dgnc_init_globals(void);
60 static int              dgnc_found_board(struct pci_dev *pdev, int id);
61 static void             dgnc_cleanup_board(struct dgnc_board *brd);
62 static void             dgnc_poll_handler(ulong dummy);
63 static int              dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
64 static void             dgnc_do_remap(struct dgnc_board *brd);
65
66 /*
67  * File operations permitted on Control/Management major.
68  */
69 static const struct file_operations dgnc_BoardFops = {
70         .owner          =       THIS_MODULE,
71         .unlocked_ioctl =       dgnc_mgmt_ioctl,
72         .open           =       dgnc_mgmt_open,
73         .release        =       dgnc_mgmt_close
74 };
75
76
77 /*
78  * Globals
79  */
80 uint                    dgnc_NumBoards;
81 struct dgnc_board               *dgnc_Board[MAXBOARDS];
82 DEFINE_SPINLOCK(dgnc_global_lock);
83 uint                    dgnc_Major;
84 int                     dgnc_poll_tick = 20;    /* Poll interval - 20 ms */
85
86 /*
87  * Static vars.
88  */
89 static struct class *dgnc_class;
90
91 /*
92  * Poller stuff
93  */
94 static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
95 static ulong            dgnc_poll_time;                         /* Time of next poll */
96 static uint             dgnc_poll_stop;                         /* Used to tell poller to stop */
97 static struct timer_list dgnc_poll_timer;
98
99
100 static struct pci_device_id dgnc_pci_tbl[] = {
101         {       DIGI_VID, PCI_DEVICE_CLASSIC_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       0 },
102         {       DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   1 },
103         {       DIGI_VID, PCI_DEVICE_CLASSIC_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       2 },
104         {       DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   3 },
105         {0,}                                            /* 0 terminated list. */
106 };
107 MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);
108
109 struct board_id {
110         unsigned char *name;
111         uint maxports;
112         unsigned int is_pci_express;
113 };
114
115 static struct board_id dgnc_Ids[] = {
116         {       PCI_DEVICE_CLASSIC_4_PCI_NAME,          4,      0       },
117         {       PCI_DEVICE_CLASSIC_4_422_PCI_NAME,      4,      0       },
118         {       PCI_DEVICE_CLASSIC_8_PCI_NAME,          8,      0       },
119         {       PCI_DEVICE_CLASSIC_8_422_PCI_NAME,      8,      0       },
120         {       PCI_DEVICE_NEO_4_PCI_NAME,              4,      0       },
121         {       PCI_DEVICE_NEO_8_PCI_NAME,              8,      0       },
122         {       PCI_DEVICE_NEO_2DB9_PCI_NAME,           2,      0       },
123         {       PCI_DEVICE_NEO_2DB9PRI_PCI_NAME,        2,      0       },
124         {       PCI_DEVICE_NEO_2RJ45_PCI_NAME,          2,      0       },
125         {       PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME,       2,      0       },
126         {       PCI_DEVICE_NEO_1_422_PCI_NAME,          1,      0       },
127         {       PCI_DEVICE_NEO_1_422_485_PCI_NAME,      1,      0       },
128         {       PCI_DEVICE_NEO_2_422_485_PCI_NAME,      2,      0       },
129         {       PCI_DEVICE_NEO_EXPRESS_8_PCI_NAME,      8,      1       },
130         {       PCI_DEVICE_NEO_EXPRESS_4_PCI_NAME,      4,      1       },
131         {       PCI_DEVICE_NEO_EXPRESS_4RJ45_PCI_NAME,  4,      1       },
132         {       PCI_DEVICE_NEO_EXPRESS_8RJ45_PCI_NAME,  8,      1       },
133         {       NULL,                                   0,      0       }
134 };
135
136 static struct pci_driver dgnc_driver = {
137         .name           = "dgnc",
138         .probe          = dgnc_init_one,
139         .id_table       = dgnc_pci_tbl,
140 };
141
142
143 char *dgnc_state_text[] = {
144         "Board Failed",
145         "Board Found",
146         "Board READY",
147 };
148
149
150 /************************************************************************
151  *
152  * Driver load/unload functions
153  *
154  ************************************************************************/
155
156 /*
157  * dgnc_cleanup_module()
158  *
159  * Module unload.  This is where it all ends.
160  */
161 static void dgnc_cleanup_module(void)
162 {
163         int i;
164         unsigned long flags;
165
166         spin_lock_irqsave(&dgnc_poll_lock, flags);
167         dgnc_poll_stop = 1;
168         spin_unlock_irqrestore(&dgnc_poll_lock, flags);
169
170         /* Turn off poller right away. */
171         del_timer_sync(&dgnc_poll_timer);
172
173         dgnc_remove_driver_sysfiles(&dgnc_driver);
174
175         device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
176         class_destroy(dgnc_class);
177         unregister_chrdev(dgnc_Major, "dgnc");
178
179         for (i = 0; i < dgnc_NumBoards; ++i) {
180                 dgnc_remove_ports_sysfiles(dgnc_Board[i]);
181                 dgnc_tty_uninit(dgnc_Board[i]);
182                 dgnc_cleanup_board(dgnc_Board[i]);
183         }
184
185         dgnc_tty_post_uninit();
186
187         if (dgnc_NumBoards)
188                 pci_unregister_driver(&dgnc_driver);
189 }
190
191 /*
192  * init_module()
193  *
194  * Module load.  This is where it all starts.
195  */
196 static int __init dgnc_init_module(void)
197 {
198         int rc = 0;
199
200         /*
201          * Initialize global stuff
202          */
203         rc = dgnc_start();
204
205         if (rc < 0)
206                 return rc;
207
208         /*
209          * Find and configure all the cards
210          */
211         rc = pci_register_driver(&dgnc_driver);
212
213         /*
214          * If something went wrong in the scan, bail out of driver.
215          */
216         if (rc < 0) {
217                 /* Only unregister the pci driver if it was actually registered. */
218                 if (dgnc_NumBoards)
219                         pci_unregister_driver(&dgnc_driver);
220                 else
221                         pr_warn("WARNING: dgnc driver load failed.  No Digi Neo or Classic boards found.\n");
222
223                 dgnc_cleanup_module();
224         } else {
225                 dgnc_create_driver_sysfiles(&dgnc_driver);
226         }
227
228         return rc;
229 }
230
231 module_init(dgnc_init_module);
232 module_exit(dgnc_cleanup_module);
233
234 /*
235  * Start of driver.
236  */
237 static int dgnc_start(void)
238 {
239         int rc = 0;
240         unsigned long flags;
241
242         /* make sure that the globals are init'd before we do anything else */
243         dgnc_init_globals();
244
245         /*
246          * Register our base character device into the kernel.
247          * This allows the download daemon to connect to the downld device
248          * before any of the boards are init'ed.
249          *
250          * Register management/dpa devices
251          */
252         rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
253         if (rc <= 0) {
254                 pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
255                 return -ENXIO;
256         }
257         dgnc_Major = rc;
258
259         dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
260         device_create(dgnc_class, NULL,
261                 MKDEV(dgnc_Major, 0),
262                 NULL, "dgnc_mgmt");
263
264         /*
265          * Init any global tty stuff.
266          */
267         rc = dgnc_tty_preinit();
268
269         if (rc < 0) {
270                 pr_err(DRVSTR ": tty preinit - not enough memory (%d)\n", rc);
271                 return rc;
272         }
273
274         /* Start the poller */
275         spin_lock_irqsave(&dgnc_poll_lock, flags);
276         init_timer(&dgnc_poll_timer);
277         dgnc_poll_timer.function = dgnc_poll_handler;
278         dgnc_poll_timer.data = 0;
279         dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
280         dgnc_poll_timer.expires = dgnc_poll_time;
281         spin_unlock_irqrestore(&dgnc_poll_lock, flags);
282
283         add_timer(&dgnc_poll_timer);
284
285         return rc;
286 }
287
288 /* returns count (>= 0), or negative on error */
289 static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
290 {
291         int rc;
292
293         /* wake up and enable device */
294         rc = pci_enable_device(pdev);
295
296         if (rc < 0) {
297                 rc = -EIO;
298         } else {
299                 rc = dgnc_found_board(pdev, ent->driver_data);
300                 if (rc == 0)
301                         dgnc_NumBoards++;
302         }
303         return rc;
304 }
305
306 /*
307  * dgnc_cleanup_board()
308  *
309  * Free all the memory associated with a board
310  */
311 static void dgnc_cleanup_board(struct dgnc_board *brd)
312 {
313         int i = 0;
314
315         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
316                 return;
317
318         switch (brd->device) {
319         case PCI_DEVICE_CLASSIC_4_DID:
320         case PCI_DEVICE_CLASSIC_8_DID:
321         case PCI_DEVICE_CLASSIC_4_422_DID:
322         case PCI_DEVICE_CLASSIC_8_422_DID:
323
324                 /* Tell card not to interrupt anymore. */
325                 outb(0, brd->iobase + 0x4c);
326                 break;
327
328         default:
329                 break;
330         }
331
332         if (brd->irq)
333                 free_irq(brd->irq, brd);
334
335         tasklet_kill(&brd->helper_tasklet);
336
337         if (brd->re_map_membase) {
338                 iounmap(brd->re_map_membase);
339                 brd->re_map_membase = NULL;
340         }
341
342         if (brd->msgbuf_head) {
343                 unsigned long flags;
344
345                 spin_lock_irqsave(&dgnc_global_lock, flags);
346                 brd->msgbuf = NULL;
347                 printk("%s", brd->msgbuf_head);
348                 kfree(brd->msgbuf_head);
349                 brd->msgbuf_head = NULL;
350                 spin_unlock_irqrestore(&dgnc_global_lock, flags);
351         }
352
353         /* Free all allocated channels structs */
354         for (i = 0; i < MAXPORTS ; i++) {
355                 if (brd->channels[i]) {
356                         kfree(brd->channels[i]->ch_rqueue);
357                         kfree(brd->channels[i]->ch_equeue);
358                         kfree(brd->channels[i]->ch_wqueue);
359                         kfree(brd->channels[i]);
360                         brd->channels[i] = NULL;
361                 }
362         }
363
364         kfree(brd->flipbuf);
365
366         dgnc_Board[brd->boardnum] = NULL;
367
368         kfree(brd);
369 }
370
371
372 /*
373  * dgnc_found_board()
374  *
375  * A board has been found, init it.
376  */
377 static int dgnc_found_board(struct pci_dev *pdev, int id)
378 {
379         struct dgnc_board *brd;
380         unsigned int pci_irq;
381         int i = 0;
382         int rc = 0;
383         unsigned long flags;
384
385         /* get the board structure and prep it */
386         dgnc_Board[dgnc_NumBoards] = kzalloc(sizeof(*brd), GFP_KERNEL);
387         brd = dgnc_Board[dgnc_NumBoards];
388
389         if (!brd)
390                 return -ENOMEM;
391
392         /* make a temporary message buffer for the boot messages */
393         brd->msgbuf_head = kzalloc(sizeof(u8) * 8192, GFP_KERNEL);
394         brd->msgbuf = brd->msgbuf_head;
395
396         if (!brd->msgbuf) {
397                 kfree(brd);
398                 return -ENOMEM;
399         }
400
401         /* store the info for the board we've found */
402         brd->magic = DGNC_BOARD_MAGIC;
403         brd->boardnum = dgnc_NumBoards;
404         brd->vendor = dgnc_pci_tbl[id].vendor;
405         brd->device = dgnc_pci_tbl[id].device;
406         brd->pdev = pdev;
407         brd->pci_bus = pdev->bus->number;
408         brd->pci_slot = PCI_SLOT(pdev->devfn);
409         brd->name = dgnc_Ids[id].name;
410         brd->maxports = dgnc_Ids[id].maxports;
411         if (dgnc_Ids[i].is_pci_express)
412                 brd->bd_flags |= BD_IS_PCI_EXPRESS;
413         brd->dpastatus = BD_NOFEP;
414         init_waitqueue_head(&brd->state_wait);
415
416         spin_lock_init(&brd->bd_lock);
417         spin_lock_init(&brd->bd_intr_lock);
418
419         brd->state              = BOARD_FOUND;
420
421         for (i = 0; i < MAXPORTS; i++)
422                 brd->channels[i] = NULL;
423
424         /* store which card & revision we have */
425         pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
426         pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
427         pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
428
429         pci_irq = pdev->irq;
430         brd->irq = pci_irq;
431
432
433         switch (brd->device) {
434
435         case PCI_DEVICE_CLASSIC_4_DID:
436         case PCI_DEVICE_CLASSIC_8_DID:
437         case PCI_DEVICE_CLASSIC_4_422_DID:
438         case PCI_DEVICE_CLASSIC_8_422_DID:
439
440                 brd->dpatype = T_CLASSIC | T_PCIBUS;
441
442                 /*
443                  * For PCI ClassicBoards
444                  * PCI Local Address (i.e. "resource" number) space
445                  * 0    PLX Memory Mapped Config
446                  * 1    PLX I/O Mapped Config
447                  * 2    I/O Mapped UARTs and Status
448                  * 3    Memory Mapped VPD
449                  * 4    Memory Mapped UARTs and Status
450                  */
451
452
453                 /* get the PCI Base Address Registers */
454                 brd->membase = pci_resource_start(pdev, 4);
455
456                 if (!brd->membase) {
457                         dev_err(&brd->pdev->dev,
458                                 "Card has no PCI IO resources, failing.\n");
459                         return -ENODEV;
460                 }
461
462                 brd->membase_end = pci_resource_end(pdev, 4);
463
464                 if (brd->membase & 1)
465                         brd->membase &= ~3;
466                 else
467                         brd->membase &= ~15;
468
469                 brd->iobase     = pci_resource_start(pdev, 1);
470                 brd->iobase_end = pci_resource_end(pdev, 1);
471                 brd->iobase     = ((unsigned int) (brd->iobase)) & 0xFFFE;
472
473                 /* Assign the board_ops struct */
474                 brd->bd_ops = &dgnc_cls_ops;
475
476                 brd->bd_uart_offset = 0x8;
477                 brd->bd_dividend = 921600;
478
479                 dgnc_do_remap(brd);
480
481                 /* Get and store the board VPD, if it exists */
482                 brd->bd_ops->vpd(brd);
483
484                 /*
485                  * Enable Local Interrupt 1               (0x1),
486                  * Local Interrupt 1 Polarity Active high (0x2),
487                  * Enable PCI interrupt                   (0x40)
488                  */
489                 outb(0x43, brd->iobase + 0x4c);
490
491                 break;
492
493
494         case PCI_DEVICE_NEO_4_DID:
495         case PCI_DEVICE_NEO_8_DID:
496         case PCI_DEVICE_NEO_2DB9_DID:
497         case PCI_DEVICE_NEO_2DB9PRI_DID:
498         case PCI_DEVICE_NEO_2RJ45_DID:
499         case PCI_DEVICE_NEO_2RJ45PRI_DID:
500         case PCI_DEVICE_NEO_1_422_DID:
501         case PCI_DEVICE_NEO_1_422_485_DID:
502         case PCI_DEVICE_NEO_2_422_485_DID:
503         case PCI_DEVICE_NEO_EXPRESS_8_DID:
504         case PCI_DEVICE_NEO_EXPRESS_4_DID:
505         case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
506         case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
507
508                 /*
509                  * This chip is set up 100% when we get to it.
510                  * No need to enable global interrupts or anything.
511                  */
512                 if (brd->bd_flags & BD_IS_PCI_EXPRESS)
513                         brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
514                 else
515                         brd->dpatype = T_NEO | T_PCIBUS;
516
517                 /* get the PCI Base Address Registers */
518                 brd->membase     = pci_resource_start(pdev, 0);
519                 brd->membase_end = pci_resource_end(pdev, 0);
520
521                 if (brd->membase & 1)
522                         brd->membase &= ~3;
523                 else
524                         brd->membase &= ~15;
525
526                 /* Assign the board_ops struct */
527                 brd->bd_ops = &dgnc_neo_ops;
528
529                 brd->bd_uart_offset = 0x200;
530                 brd->bd_dividend = 921600;
531
532                 dgnc_do_remap(brd);
533
534                 if (brd->re_map_membase) {
535
536                         /* After remap is complete, we need to read and store the dvid */
537                         brd->dvid = readb(brd->re_map_membase + 0x8D);
538
539                         /* Get and store the board VPD, if it exists */
540                         brd->bd_ops->vpd(brd);
541                 }
542                 break;
543
544         default:
545                 dev_err(&brd->pdev->dev,
546                         "Didn't find any compatible Neo/Classic PCI boards.\n");
547                 return -ENXIO;
548
549         }
550
551         /*
552          * Do tty device initialization.
553          */
554
555         rc = dgnc_tty_register(brd);
556         if (rc < 0) {
557                 dgnc_tty_uninit(brd);
558                 pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
559                 brd->state = BOARD_FAILED;
560                 brd->dpastatus = BD_NOFEP;
561                 goto failed;
562         }
563
564         rc = dgnc_finalize_board_init(brd);
565         if (rc < 0) {
566                 pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
567                 brd->state = BOARD_FAILED;
568                 brd->dpastatus = BD_NOFEP;
569
570                 goto failed;
571         }
572
573         rc = dgnc_tty_init(brd);
574         if (rc < 0) {
575                 dgnc_tty_uninit(brd);
576                 pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
577                 brd->state = BOARD_FAILED;
578                 brd->dpastatus = BD_NOFEP;
579
580                 goto failed;
581         }
582
583         brd->state = BOARD_READY;
584         brd->dpastatus = BD_RUNNING;
585
586         dgnc_create_ports_sysfiles(brd);
587
588         /* init our poll helper tasklet */
589         tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, (unsigned long) brd);
590
591         spin_lock_irqsave(&dgnc_global_lock, flags);
592         brd->msgbuf = NULL;
593         printk("%s", brd->msgbuf_head);
594         kfree(brd->msgbuf_head);
595         brd->msgbuf_head = NULL;
596         spin_unlock_irqrestore(&dgnc_global_lock, flags);
597
598         /*
599          * allocate flip buffer for board.
600          *
601          * Okay to malloc with GFP_KERNEL, we are not at interrupt
602          * context, and there are no locks held.
603          */
604         brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
605
606         wake_up_interruptible(&brd->state_wait);
607
608         return 0;
609
610 failed:
611
612         return -ENXIO;
613
614 }
615
616
617 static int dgnc_finalize_board_init(struct dgnc_board *brd)
618 {
619         int rc = 0;
620
621         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
622                 return -ENODEV;
623
624         if (brd->irq) {
625                 rc = request_irq(brd->irq, brd->bd_ops->intr,
626                                  IRQF_SHARED, "DGNC", brd);
627
628                 if (rc) {
629                         dev_err(&brd->pdev->dev,
630                                 "Failed to hook IRQ %d\n", brd->irq);
631                         brd->state = BOARD_FAILED;
632                         brd->dpastatus = BD_NOFEP;
633                         rc = -ENODEV;
634                 }
635         }
636         return rc;
637 }
638
639 /*
640  * Remap PCI memory.
641  */
642 static void dgnc_do_remap(struct dgnc_board *brd)
643 {
644
645         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
646                 return;
647
648         brd->re_map_membase = ioremap(brd->membase, 0x1000);
649 }
650
651
652 /*****************************************************************************
653 *
654 * Function:
655 *
656 *    dgnc_poll_handler
657 *
658 * Author:
659 *
660 *    Scott H Kilau
661 *
662 * Parameters:
663 *
664 *    dummy -- ignored
665 *
666 * Return Values:
667 *
668 *    none
669 *
670 * Description:
671 *
672 *    As each timer expires, it determines (a) whether the "transmit"
673 *    waiter needs to be woken up, and (b) whether the poller needs to
674 *    be rescheduled.
675 *
676 ******************************************************************************/
677
678 static void dgnc_poll_handler(ulong dummy)
679 {
680         struct dgnc_board *brd;
681         unsigned long flags;
682         int i;
683         unsigned long new_time;
684
685         /* Go thru each board, kicking off a tasklet for each if needed */
686         for (i = 0; i < dgnc_NumBoards; i++) {
687                 brd = dgnc_Board[i];
688
689                 spin_lock_irqsave(&brd->bd_lock, flags);
690
691                 /* If board is in a failed state, don't bother scheduling a tasklet */
692                 if (brd->state == BOARD_FAILED) {
693                         spin_unlock_irqrestore(&brd->bd_lock, flags);
694                         continue;
695                 }
696
697                 /* Schedule a poll helper task */
698                 tasklet_schedule(&brd->helper_tasklet);
699
700                 spin_unlock_irqrestore(&brd->bd_lock, flags);
701         }
702
703         /*
704          * Schedule ourself back at the nominal wakeup interval.
705          */
706         spin_lock_irqsave(&dgnc_poll_lock, flags);
707         dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
708
709         new_time = dgnc_poll_time - jiffies;
710
711         if ((ulong) new_time >= 2 * dgnc_poll_tick)
712                 dgnc_poll_time = jiffies +  dgnc_jiffies_from_ms(dgnc_poll_tick);
713
714         init_timer(&dgnc_poll_timer);
715         dgnc_poll_timer.function = dgnc_poll_handler;
716         dgnc_poll_timer.data = 0;
717         dgnc_poll_timer.expires = dgnc_poll_time;
718         spin_unlock_irqrestore(&dgnc_poll_lock, flags);
719
720         if (!dgnc_poll_stop)
721                 add_timer(&dgnc_poll_timer);
722 }
723
724 /*
725  * dgnc_init_globals()
726  *
727  * This is where we initialize the globals from the static insmod
728  * configuration variables.  These are declared near the head of
729  * this file.
730  */
731 static void dgnc_init_globals(void)
732 {
733         int i = 0;
734
735         dgnc_NumBoards          = 0;
736
737         for (i = 0; i < MAXBOARDS; i++)
738                 dgnc_Board[i] = NULL;
739
740         init_timer(&dgnc_poll_timer);
741 }
742