Version:  2.0.40 2.2.26 2.4.37 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0

Linux/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 const struct pci_device_id dgnc_pci_tbl[] = {
101         {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID),     .driver_data = 0},
102         {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1},
103         {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_DID),     .driver_data = 2},
104         {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID), .driver_data = 3},
105         {0,}
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         struct device *dev;
242 
243         /* make sure that the globals are init'd before we do anything else */
244         dgnc_init_globals();
245 
246         /*
247          * Register our base character device into the kernel.
248          * This allows the download daemon to connect to the downld device
249          * before any of the boards are init'ed.
250          *
251          * Register management/dpa devices
252          */
253         rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
254         if (rc <= 0) {
255                 pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
256                 return -ENXIO;
257         }
258         dgnc_Major = rc;
259 
260         dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
261         if (IS_ERR(dgnc_class)) {
262                 rc = PTR_ERR(dgnc_class);
263                 pr_err(DRVSTR ": Can't create dgnc_mgmt class (%d)\n", rc);
264                 goto failed_class;
265         }
266 
267         dev = device_create(dgnc_class, NULL,
268                         MKDEV(dgnc_Major, 0),
269                         NULL, "dgnc_mgmt");
270         if (IS_ERR(dev)) {
271                 rc = PTR_ERR(dev);
272                 pr_err(DRVSTR ": Can't create device (%d)\n", rc);
273                 goto failed_device;
274         }
275 
276         /*
277          * Init any global tty stuff.
278          */
279         rc = dgnc_tty_preinit();
280 
281         if (rc < 0) {
282                 pr_err(DRVSTR ": tty preinit - not enough memory (%d)\n", rc);
283                 goto failed_tty;
284         }
285 
286         /* Start the poller */
287         spin_lock_irqsave(&dgnc_poll_lock, flags);
288         init_timer(&dgnc_poll_timer);
289         dgnc_poll_timer.function = dgnc_poll_handler;
290         dgnc_poll_timer.data = 0;
291         dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
292         dgnc_poll_timer.expires = dgnc_poll_time;
293         spin_unlock_irqrestore(&dgnc_poll_lock, flags);
294 
295         add_timer(&dgnc_poll_timer);
296 
297         return 0;
298 
299 failed_tty:
300         device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
301 failed_device:
302         class_destroy(dgnc_class);
303 failed_class:
304         unregister_chrdev(dgnc_Major, "dgnc");
305         return rc;
306 }
307 
308 /* returns count (>= 0), or negative on error */
309 static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
310 {
311         int rc;
312 
313         /* wake up and enable device */
314         rc = pci_enable_device(pdev);
315 
316         if (rc < 0) {
317                 rc = -EIO;
318         } else {
319                 rc = dgnc_found_board(pdev, ent->driver_data);
320                 if (rc == 0)
321                         dgnc_NumBoards++;
322         }
323         return rc;
324 }
325 
326 /*
327  * dgnc_cleanup_board()
328  *
329  * Free all the memory associated with a board
330  */
331 static void dgnc_cleanup_board(struct dgnc_board *brd)
332 {
333         int i = 0;
334 
335         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
336                 return;
337 
338         switch (brd->device) {
339         case PCI_DEVICE_CLASSIC_4_DID:
340         case PCI_DEVICE_CLASSIC_8_DID:
341         case PCI_DEVICE_CLASSIC_4_422_DID:
342         case PCI_DEVICE_CLASSIC_8_422_DID:
343 
344                 /* Tell card not to interrupt anymore. */
345                 outb(0, brd->iobase + 0x4c);
346                 break;
347 
348         default:
349                 break;
350         }
351 
352         if (brd->irq)
353                 free_irq(brd->irq, brd);
354 
355         tasklet_kill(&brd->helper_tasklet);
356 
357         if (brd->re_map_membase) {
358                 iounmap(brd->re_map_membase);
359                 brd->re_map_membase = NULL;
360         }
361 
362         if (brd->msgbuf_head) {
363                 unsigned long flags;
364 
365                 spin_lock_irqsave(&dgnc_global_lock, flags);
366                 brd->msgbuf = NULL;
367                 printk("%s", brd->msgbuf_head);
368                 kfree(brd->msgbuf_head);
369                 brd->msgbuf_head = NULL;
370                 spin_unlock_irqrestore(&dgnc_global_lock, flags);
371         }
372 
373         /* Free all allocated channels structs */
374         for (i = 0; i < MAXPORTS ; i++) {
375                 if (brd->channels[i]) {
376                         kfree(brd->channels[i]->ch_rqueue);
377                         kfree(brd->channels[i]->ch_equeue);
378                         kfree(brd->channels[i]->ch_wqueue);
379                         kfree(brd->channels[i]);
380                         brd->channels[i] = NULL;
381                 }
382         }
383 
384         kfree(brd->flipbuf);
385 
386         dgnc_Board[brd->boardnum] = NULL;
387 
388         kfree(brd);
389 }
390 
391 
392 /*
393  * dgnc_found_board()
394  *
395  * A board has been found, init it.
396  */
397 static int dgnc_found_board(struct pci_dev *pdev, int id)
398 {
399         struct dgnc_board *brd;
400         unsigned int pci_irq;
401         int i = 0;
402         int rc = 0;
403         unsigned long flags;
404 
405         /* get the board structure and prep it */
406         dgnc_Board[dgnc_NumBoards] = kzalloc(sizeof(*brd), GFP_KERNEL);
407         brd = dgnc_Board[dgnc_NumBoards];
408 
409         if (!brd)
410                 return -ENOMEM;
411 
412         /* make a temporary message buffer for the boot messages */
413         brd->msgbuf_head = kzalloc(sizeof(u8) * 8192, GFP_KERNEL);
414         brd->msgbuf = brd->msgbuf_head;
415 
416         if (!brd->msgbuf) {
417                 kfree(brd);
418                 return -ENOMEM;
419         }
420 
421         /* store the info for the board we've found */
422         brd->magic = DGNC_BOARD_MAGIC;
423         brd->boardnum = dgnc_NumBoards;
424         brd->vendor = dgnc_pci_tbl[id].vendor;
425         brd->device = dgnc_pci_tbl[id].device;
426         brd->pdev = pdev;
427         brd->pci_bus = pdev->bus->number;
428         brd->pci_slot = PCI_SLOT(pdev->devfn);
429         brd->name = dgnc_Ids[id].name;
430         brd->maxports = dgnc_Ids[id].maxports;
431         if (dgnc_Ids[i].is_pci_express)
432                 brd->bd_flags |= BD_IS_PCI_EXPRESS;
433         brd->dpastatus = BD_NOFEP;
434         init_waitqueue_head(&brd->state_wait);
435 
436         spin_lock_init(&brd->bd_lock);
437         spin_lock_init(&brd->bd_intr_lock);
438 
439         brd->state              = BOARD_FOUND;
440 
441         for (i = 0; i < MAXPORTS; i++)
442                 brd->channels[i] = NULL;
443 
444         /* store which card & revision we have */
445         pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
446         pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
447         pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
448 
449         pci_irq = pdev->irq;
450         brd->irq = pci_irq;
451 
452 
453         switch (brd->device) {
454 
455         case PCI_DEVICE_CLASSIC_4_DID:
456         case PCI_DEVICE_CLASSIC_8_DID:
457         case PCI_DEVICE_CLASSIC_4_422_DID:
458         case PCI_DEVICE_CLASSIC_8_422_DID:
459 
460                 brd->dpatype = T_CLASSIC | T_PCIBUS;
461 
462                 /*
463                  * For PCI ClassicBoards
464                  * PCI Local Address (i.e. "resource" number) space
465                  * 0    PLX Memory Mapped Config
466                  * 1    PLX I/O Mapped Config
467                  * 2    I/O Mapped UARTs and Status
468                  * 3    Memory Mapped VPD
469                  * 4    Memory Mapped UARTs and Status
470                  */
471 
472 
473                 /* get the PCI Base Address Registers */
474                 brd->membase = pci_resource_start(pdev, 4);
475 
476                 if (!brd->membase) {
477                         dev_err(&brd->pdev->dev,
478                                 "Card has no PCI IO resources, failing.\n");
479                         return -ENODEV;
480                 }
481 
482                 brd->membase_end = pci_resource_end(pdev, 4);
483 
484                 if (brd->membase & 1)
485                         brd->membase &= ~3;
486                 else
487                         brd->membase &= ~15;
488 
489                 brd->iobase     = pci_resource_start(pdev, 1);
490                 brd->iobase_end = pci_resource_end(pdev, 1);
491                 brd->iobase     = ((unsigned int) (brd->iobase)) & 0xFFFE;
492 
493                 /* Assign the board_ops struct */
494                 brd->bd_ops = &dgnc_cls_ops;
495 
496                 brd->bd_uart_offset = 0x8;
497                 brd->bd_dividend = 921600;
498 
499                 dgnc_do_remap(brd);
500 
501                 /* Get and store the board VPD, if it exists */
502                 brd->bd_ops->vpd(brd);
503 
504                 /*
505                  * Enable Local Interrupt 1               (0x1),
506                  * Local Interrupt 1 Polarity Active high (0x2),
507                  * Enable PCI interrupt                   (0x40)
508                  */
509                 outb(0x43, brd->iobase + 0x4c);
510 
511                 break;
512 
513 
514         case PCI_DEVICE_NEO_4_DID:
515         case PCI_DEVICE_NEO_8_DID:
516         case PCI_DEVICE_NEO_2DB9_DID:
517         case PCI_DEVICE_NEO_2DB9PRI_DID:
518         case PCI_DEVICE_NEO_2RJ45_DID:
519         case PCI_DEVICE_NEO_2RJ45PRI_DID:
520         case PCI_DEVICE_NEO_1_422_DID:
521         case PCI_DEVICE_NEO_1_422_485_DID:
522         case PCI_DEVICE_NEO_2_422_485_DID:
523         case PCI_DEVICE_NEO_EXPRESS_8_DID:
524         case PCI_DEVICE_NEO_EXPRESS_4_DID:
525         case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
526         case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
527 
528                 /*
529                  * This chip is set up 100% when we get to it.
530                  * No need to enable global interrupts or anything.
531                  */
532                 if (brd->bd_flags & BD_IS_PCI_EXPRESS)
533                         brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
534                 else
535                         brd->dpatype = T_NEO | T_PCIBUS;
536 
537                 /* get the PCI Base Address Registers */
538                 brd->membase     = pci_resource_start(pdev, 0);
539                 brd->membase_end = pci_resource_end(pdev, 0);
540 
541                 if (brd->membase & 1)
542                         brd->membase &= ~3;
543                 else
544                         brd->membase &= ~15;
545 
546                 /* Assign the board_ops struct */
547                 brd->bd_ops = &dgnc_neo_ops;
548 
549                 brd->bd_uart_offset = 0x200;
550                 brd->bd_dividend = 921600;
551 
552                 dgnc_do_remap(brd);
553 
554                 if (brd->re_map_membase) {
555 
556                         /* After remap is complete, we need to read and store the dvid */
557                         brd->dvid = readb(brd->re_map_membase + 0x8D);
558 
559                         /* Get and store the board VPD, if it exists */
560                         brd->bd_ops->vpd(brd);
561                 }
562                 break;
563 
564         default:
565                 dev_err(&brd->pdev->dev,
566                         "Didn't find any compatible Neo/Classic PCI boards.\n");
567                 return -ENXIO;
568 
569         }
570 
571         /*
572          * Do tty device initialization.
573          */
574 
575         rc = dgnc_tty_register(brd);
576         if (rc < 0) {
577                 dgnc_tty_uninit(brd);
578                 pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
579                 brd->state = BOARD_FAILED;
580                 brd->dpastatus = BD_NOFEP;
581                 goto failed;
582         }
583 
584         rc = dgnc_finalize_board_init(brd);
585         if (rc < 0) {
586                 pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
587                 brd->state = BOARD_FAILED;
588                 brd->dpastatus = BD_NOFEP;
589 
590                 goto failed;
591         }
592 
593         rc = dgnc_tty_init(brd);
594         if (rc < 0) {
595                 dgnc_tty_uninit(brd);
596                 pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
597                 brd->state = BOARD_FAILED;
598                 brd->dpastatus = BD_NOFEP;
599 
600                 goto failed;
601         }
602 
603         brd->state = BOARD_READY;
604         brd->dpastatus = BD_RUNNING;
605 
606         dgnc_create_ports_sysfiles(brd);
607 
608         /* init our poll helper tasklet */
609         tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, (unsigned long) brd);
610 
611         spin_lock_irqsave(&dgnc_global_lock, flags);
612         brd->msgbuf = NULL;
613         printk("%s", brd->msgbuf_head);
614         kfree(brd->msgbuf_head);
615         brd->msgbuf_head = NULL;
616         spin_unlock_irqrestore(&dgnc_global_lock, flags);
617 
618         /*
619          * allocate flip buffer for board.
620          *
621          * Okay to malloc with GFP_KERNEL, we are not at interrupt
622          * context, and there are no locks held.
623          */
624         brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
625 
626         wake_up_interruptible(&brd->state_wait);
627 
628         return 0;
629 
630 failed:
631 
632         return -ENXIO;
633 
634 }
635 
636 
637 static int dgnc_finalize_board_init(struct dgnc_board *brd)
638 {
639         int rc = 0;
640 
641         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
642                 return -ENODEV;
643 
644         if (brd->irq) {
645                 rc = request_irq(brd->irq, brd->bd_ops->intr,
646                                  IRQF_SHARED, "DGNC", brd);
647 
648                 if (rc) {
649                         dev_err(&brd->pdev->dev,
650                                 "Failed to hook IRQ %d\n", brd->irq);
651                         brd->state = BOARD_FAILED;
652                         brd->dpastatus = BD_NOFEP;
653                         rc = -ENODEV;
654                 }
655         }
656         return rc;
657 }
658 
659 /*
660  * Remap PCI memory.
661  */
662 static void dgnc_do_remap(struct dgnc_board *brd)
663 {
664 
665         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
666                 return;
667 
668         brd->re_map_membase = ioremap(brd->membase, 0x1000);
669 }
670 
671 
672 /*****************************************************************************
673 *
674 * Function:
675 *
676 *    dgnc_poll_handler
677 *
678 * Author:
679 *
680 *    Scott H Kilau
681 *
682 * Parameters:
683 *
684 *    dummy -- ignored
685 *
686 * Return Values:
687 *
688 *    none
689 *
690 * Description:
691 *
692 *    As each timer expires, it determines (a) whether the "transmit"
693 *    waiter needs to be woken up, and (b) whether the poller needs to
694 *    be rescheduled.
695 *
696 ******************************************************************************/
697 
698 static void dgnc_poll_handler(ulong dummy)
699 {
700         struct dgnc_board *brd;
701         unsigned long flags;
702         int i;
703         unsigned long new_time;
704 
705         /* Go thru each board, kicking off a tasklet for each if needed */
706         for (i = 0; i < dgnc_NumBoards; i++) {
707                 brd = dgnc_Board[i];
708 
709                 spin_lock_irqsave(&brd->bd_lock, flags);
710 
711                 /* If board is in a failed state, don't bother scheduling a tasklet */
712                 if (brd->state == BOARD_FAILED) {
713                         spin_unlock_irqrestore(&brd->bd_lock, flags);
714                         continue;
715                 }
716 
717                 /* Schedule a poll helper task */
718                 tasklet_schedule(&brd->helper_tasklet);
719 
720                 spin_unlock_irqrestore(&brd->bd_lock, flags);
721         }
722 
723         /*
724          * Schedule ourself back at the nominal wakeup interval.
725          */
726         spin_lock_irqsave(&dgnc_poll_lock, flags);
727         dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
728 
729         new_time = dgnc_poll_time - jiffies;
730 
731         if ((ulong) new_time >= 2 * dgnc_poll_tick)
732                 dgnc_poll_time = jiffies +  dgnc_jiffies_from_ms(dgnc_poll_tick);
733 
734         init_timer(&dgnc_poll_timer);
735         dgnc_poll_timer.function = dgnc_poll_handler;
736         dgnc_poll_timer.data = 0;
737         dgnc_poll_timer.expires = dgnc_poll_time;
738         spin_unlock_irqrestore(&dgnc_poll_lock, flags);
739 
740         if (!dgnc_poll_stop)
741                 add_timer(&dgnc_poll_timer);
742 }
743 
744 /*
745  * dgnc_init_globals()
746  *
747  * This is where we initialize the globals from the static insmod
748  * configuration variables.  These are declared near the head of
749  * this file.
750  */
751 static void dgnc_init_globals(void)
752 {
753         int i = 0;
754 
755         dgnc_NumBoards          = 0;
756 
757         for (i = 0; i < MAXBOARDS; i++)
758                 dgnc_Board[i] = NULL;
759 
760         init_timer(&dgnc_poll_timer);
761 }
762 
763 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us