Version:  2.0.40 2.2.26 2.4.37 3.1 3.2 3.3 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

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  * insmod command line overrideable parameters
 54  *
 55  * NOTE: we use a set of macros to create the variables, which allows
 56  * us to specify the variable type, name, initial value, and description.
 57  */
 58 PARM_INT(debug,         0x00,           0644,   "Driver debugging level");
 59 PARM_INT(rawreadok,     1,              0644,   "Bypass flip buffers on input");
 60 PARM_INT(trcbuf_size,   0x100000,       0644,   "Debugging trace buffer size.");
 61 
 62 /**************************************************************************
 63  *
 64  * protos for this file
 65  *
 66  */
 67 static int              dgnc_start(void);
 68 static int              dgnc_finalize_board_init(struct dgnc_board *brd);
 69 static void             dgnc_init_globals(void);
 70 static int              dgnc_found_board(struct pci_dev *pdev, int id);
 71 static void             dgnc_cleanup_board(struct dgnc_board *brd);
 72 static void             dgnc_poll_handler(ulong dummy);
 73 static int              dgnc_init_pci(void);
 74 static int              dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
 75 static void             dgnc_remove_one(struct pci_dev *dev);
 76 static int              dgnc_probe1(struct pci_dev *pdev, int card_type);
 77 static void             dgnc_do_remap(struct dgnc_board *brd);
 78 
 79 /* Driver load/unload functions */
 80 int             dgnc_init_module(void);
 81 void            dgnc_cleanup_module(void);
 82 
 83 module_init(dgnc_init_module);
 84 module_exit(dgnc_cleanup_module);
 85 
 86 
 87 /*
 88  * File operations permitted on Control/Management major.
 89  */
 90 static const struct file_operations dgnc_BoardFops = {
 91         .owner          =       THIS_MODULE,
 92         .unlocked_ioctl =       dgnc_mgmt_ioctl,
 93         .open           =       dgnc_mgmt_open,
 94         .release        =       dgnc_mgmt_close
 95 };
 96 
 97 
 98 /*
 99  * Globals
100  */
101 uint                    dgnc_NumBoards;
102 struct dgnc_board               *dgnc_Board[MAXBOARDS];
103 DEFINE_SPINLOCK(dgnc_global_lock);
104 int                     dgnc_driver_state = DRIVER_INITIALIZED;
105 ulong                   dgnc_poll_counter;
106 uint                    dgnc_Major;
107 int                     dgnc_poll_tick = 20;    /* Poll interval - 20 ms */
108 
109 /*
110  * Static vars.
111  */
112 static uint             dgnc_Major_Control_Registered = FALSE;
113 static uint             dgnc_driver_start = FALSE;
114 
115 static struct class *dgnc_class;
116 
117 /*
118  * Poller stuff
119  */
120 static                  DEFINE_SPINLOCK(dgnc_poll_lock);        /* Poll scheduling lock */
121 static ulong            dgnc_poll_time;                         /* Time of next poll */
122 static uint             dgnc_poll_stop;                         /* Used to tell poller to stop */
123 static struct timer_list dgnc_poll_timer;
124 
125 
126 static struct pci_device_id dgnc_pci_tbl[] = {
127         {       DIGI_VID, PCI_DEVICE_CLASSIC_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       0 },
128         {       DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   1 },
129         {       DIGI_VID, PCI_DEVICE_CLASSIC_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       2 },
130         {       DIGI_VID, PCI_DEVICE_CLASSIC_8_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   3 },
131         {       DIGI_VID, PCI_DEVICE_NEO_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,           4 },
132         {       DIGI_VID, PCI_DEVICE_NEO_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,           5 },
133         {       DIGI_VID, PCI_DEVICE_NEO_2DB9_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,        6 },
134         {       DIGI_VID, PCI_DEVICE_NEO_2DB9PRI_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,     7 },
135         {       DIGI_VID, PCI_DEVICE_NEO_2RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       8 },
136         {       DIGI_VID, PCI_DEVICE_NEO_2RJ45PRI_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,    9 },
137         {       DIGI_VID, PCI_DEVICE_NEO_1_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       10 },
138         {       DIGI_VID, PCI_DEVICE_NEO_1_422_485_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   11 },
139         {       DIGI_VID, PCI_DEVICE_NEO_2_422_485_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   12 },
140         {       DIGI_VID, PCI_DEVICE_NEO_EXPRESS_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,    13 },
141         {       DIGI_VID, PCI_DEVICE_NEO_EXPRESS_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,   14 },
142         {       DIGI_VID, PCI_DEVICE_NEO_EXPRESS_4RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       15 },
143         {       DIGI_VID, PCI_DEVICE_NEO_EXPRESS_8RJ45_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0,       16 },
144         {0,}                                            /* 0 terminated list. */
145 };
146 MODULE_DEVICE_TABLE(pci, dgnc_pci_tbl);
147 
148 struct board_id {
149         uchar *name;
150         uint maxports;
151         unsigned int is_pci_express;
152 };
153 
154 static struct board_id dgnc_Ids[] = {
155         {       PCI_DEVICE_CLASSIC_4_PCI_NAME,          4,      0       },
156         {       PCI_DEVICE_CLASSIC_4_422_PCI_NAME,      4,      0       },
157         {       PCI_DEVICE_CLASSIC_8_PCI_NAME,          8,      0       },
158         {       PCI_DEVICE_CLASSIC_8_422_PCI_NAME,      8,      0       },
159         {       PCI_DEVICE_NEO_4_PCI_NAME,              4,      0       },
160         {       PCI_DEVICE_NEO_8_PCI_NAME,              8,      0       },
161         {       PCI_DEVICE_NEO_2DB9_PCI_NAME,           2,      0       },
162         {       PCI_DEVICE_NEO_2DB9PRI_PCI_NAME,        2,      0       },
163         {       PCI_DEVICE_NEO_2RJ45_PCI_NAME,          2,      0       },
164         {       PCI_DEVICE_NEO_2RJ45PRI_PCI_NAME,       2,      0       },
165         {       PCI_DEVICE_NEO_1_422_PCI_NAME,          1,      0       },
166         {       PCI_DEVICE_NEO_1_422_485_PCI_NAME,      1,      0       },
167         {       PCI_DEVICE_NEO_2_422_485_PCI_NAME,      2,      0       },
168         {       PCI_DEVICE_NEO_EXPRESS_8_PCI_NAME,      8,      1       },
169         {       PCI_DEVICE_NEO_EXPRESS_4_PCI_NAME,      4,      1       },
170         {       PCI_DEVICE_NEO_EXPRESS_4RJ45_PCI_NAME,  4,      1       },
171         {       PCI_DEVICE_NEO_EXPRESS_8RJ45_PCI_NAME,  8,      1       },
172         {       NULL,                                   0,      0       }
173 };
174 
175 static struct pci_driver dgnc_driver = {
176         .name           = "dgnc",
177         .probe          = dgnc_init_one,
178         .id_table       = dgnc_pci_tbl,
179         .remove         = dgnc_remove_one,
180 };
181 
182 
183 char *dgnc_state_text[] = {
184         "Board Failed",
185         "Board Found",
186         "Board READY",
187 };
188 
189 char *dgnc_driver_state_text[] = {
190         "Driver Initialized",
191         "Driver Ready."
192 };
193 
194 
195 
196 /************************************************************************
197  *
198  * Driver load/unload functions
199  *
200  ************************************************************************/
201 
202 
203 /*
204  * init_module()
205  *
206  * Module load.  This is where it all starts.
207  */
208 int dgnc_init_module(void)
209 {
210         int rc = 0;
211 
212         APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
213 
214         /*
215          * Initialize global stuff
216          */
217         rc = dgnc_start();
218 
219         if (rc < 0)
220                 return rc;
221 
222         /*
223          * Find and configure all the cards
224          */
225         rc = dgnc_init_pci();
226 
227         /*
228          * If something went wrong in the scan, bail out of driver.
229          */
230         if (rc < 0) {
231                 /* Only unregister the pci driver if it was actually registered. */
232                 if (dgnc_NumBoards)
233                         pci_unregister_driver(&dgnc_driver);
234                 else
235                         pr_warn("WARNING: dgnc driver load failed.  No Digi Neo or Classic boards found.\n");
236 
237                 dgnc_cleanup_module();
238         } else {
239                 dgnc_create_driver_sysfiles(&dgnc_driver);
240         }
241 
242         DPR_INIT(("Finished init_module. Returning %d\n", rc));
243         return rc;
244 }
245 
246 
247 /*
248  * Start of driver.
249  */
250 static int dgnc_start(void)
251 {
252         int rc = 0;
253         unsigned long flags;
254 
255         if (dgnc_driver_start == FALSE) {
256 
257                 dgnc_driver_start = TRUE;
258 
259                 /* make sure that the globals are init'd before we do anything else */
260                 dgnc_init_globals();
261 
262                 dgnc_NumBoards = 0;
263 
264                 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
265 
266                 /*
267                  * Register our base character device into the kernel.
268                  * This allows the download daemon to connect to the downld device
269                  * before any of the boards are init'ed.
270                  */
271                 if (!dgnc_Major_Control_Registered) {
272                         /*
273                          * Register management/dpa devices
274                          */
275                         rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
276                         if (rc <= 0) {
277                                 APR(("Can't register dgnc driver device (%d)\n", rc));
278                                 rc = -ENXIO;
279                                 return rc;
280                         }
281                         dgnc_Major = rc;
282 
283                         dgnc_class = class_create(THIS_MODULE, "dgnc_mgmt");
284                         device_create(dgnc_class, NULL,
285                                 MKDEV(dgnc_Major, 0),
286                                 NULL, "dgnc_mgmt");
287                         dgnc_Major_Control_Registered = TRUE;
288                 }
289 
290                 /*
291                  * Init any global tty stuff.
292                  */
293                 rc = dgnc_tty_preinit();
294 
295                 if (rc < 0) {
296                         APR(("tty preinit - not enough memory (%d)\n", rc));
297                         return rc;
298                 }
299 
300                 /* Start the poller */
301                 DGNC_LOCK(dgnc_poll_lock, flags);
302                 init_timer(&dgnc_poll_timer);
303                 dgnc_poll_timer.function = dgnc_poll_handler;
304                 dgnc_poll_timer.data = 0;
305                 dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
306                 dgnc_poll_timer.expires = dgnc_poll_time;
307                 DGNC_UNLOCK(dgnc_poll_lock, flags);
308 
309                 add_timer(&dgnc_poll_timer);
310 
311                 dgnc_driver_state = DRIVER_READY;
312         }
313 
314         return rc;
315 }
316 
317 /*
318  * Register pci driver, and return how many boards we have.
319  */
320 static int dgnc_init_pci(void)
321 {
322         return pci_register_driver(&dgnc_driver);
323 }
324 
325 
326 /* returns count (>= 0), or negative on error */
327 static int dgnc_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
328 {
329         int rc;
330 
331         /* wake up and enable device */
332         rc = pci_enable_device(pdev);
333 
334         if (rc < 0) {
335                 rc = -EIO;
336         } else {
337                 rc = dgnc_probe1(pdev, ent->driver_data);
338                 if (rc == 0) {
339                         dgnc_NumBoards++;
340                         DPR_INIT(("Incrementing numboards to %d\n", dgnc_NumBoards));
341                 }
342         }
343         return rc;
344 }
345 
346 static int dgnc_probe1(struct pci_dev *pdev, int card_type)
347 {
348         return dgnc_found_board(pdev, card_type);
349 }
350 
351 
352 static void dgnc_remove_one(struct pci_dev *dev)
353 {
354         /* Do Nothing */
355 }
356 
357 /*
358  * dgnc_cleanup_module()
359  *
360  * Module unload.  This is where it all ends.
361  */
362 void dgnc_cleanup_module(void)
363 {
364         int i;
365         ulong lock_flags;
366 
367         DGNC_LOCK(dgnc_poll_lock, lock_flags);
368         dgnc_poll_stop = 1;
369         DGNC_UNLOCK(dgnc_poll_lock, lock_flags);
370 
371         /* Turn off poller right away. */
372         del_timer_sync(&dgnc_poll_timer);
373 
374         dgnc_remove_driver_sysfiles(&dgnc_driver);
375 
376         if (dgnc_Major_Control_Registered) {
377                 device_destroy(dgnc_class, MKDEV(dgnc_Major, 0));
378                 class_destroy(dgnc_class);
379                 unregister_chrdev(dgnc_Major, "dgnc");
380         }
381 
382         for (i = 0; i < dgnc_NumBoards; ++i) {
383                 dgnc_remove_ports_sysfiles(dgnc_Board[i]);
384                 dgnc_tty_uninit(dgnc_Board[i]);
385                 dgnc_cleanup_board(dgnc_Board[i]);
386         }
387 
388         dgnc_tty_post_uninit();
389 
390         if (dgnc_NumBoards)
391                 pci_unregister_driver(&dgnc_driver);
392 }
393 
394 
395 /*
396  * dgnc_cleanup_board()
397  *
398  * Free all the memory associated with a board
399  */
400 static void dgnc_cleanup_board(struct dgnc_board *brd)
401 {
402         int i = 0;
403 
404         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
405                 return;
406 
407         switch (brd->device) {
408         case PCI_DEVICE_CLASSIC_4_DID:
409         case PCI_DEVICE_CLASSIC_8_DID:
410         case PCI_DEVICE_CLASSIC_4_422_DID:
411         case PCI_DEVICE_CLASSIC_8_422_DID:
412 
413                 /* Tell card not to interrupt anymore. */
414                 outb(0, brd->iobase + 0x4c);
415                 break;
416 
417         default:
418                 break;
419         }
420 
421         if (brd->irq)
422                 free_irq(brd->irq, brd);
423 
424         tasklet_kill(&brd->helper_tasklet);
425 
426         if (brd->re_map_membase) {
427                 iounmap(brd->re_map_membase);
428                 brd->re_map_membase = NULL;
429         }
430 
431         if (brd->msgbuf_head) {
432                 unsigned long flags;
433 
434                 DGNC_LOCK(dgnc_global_lock, flags);
435                 brd->msgbuf = NULL;
436                 printk("%s", brd->msgbuf_head);
437                 kfree(brd->msgbuf_head);
438                 brd->msgbuf_head = NULL;
439                 DGNC_UNLOCK(dgnc_global_lock, flags);
440         }
441 
442         /* Free all allocated channels structs */
443         for (i = 0; i < MAXPORTS ; i++) {
444                 if (brd->channels[i]) {
445                         kfree(brd->channels[i]->ch_rqueue);
446                         kfree(brd->channels[i]->ch_equeue);
447                         kfree(brd->channels[i]->ch_wqueue);
448                         kfree(brd->channels[i]);
449                         brd->channels[i] = NULL;
450                 }
451         }
452 
453         kfree(brd->flipbuf);
454 
455         dgnc_Board[brd->boardnum] = NULL;
456 
457         kfree(brd);
458 }
459 
460 
461 /*
462  * dgnc_found_board()
463  *
464  * A board has been found, init it.
465  */
466 static int dgnc_found_board(struct pci_dev *pdev, int id)
467 {
468         struct dgnc_board *brd;
469         unsigned int pci_irq;
470         int i = 0;
471         int rc = 0;
472         unsigned long flags;
473 
474         /* get the board structure and prep it */
475         brd = dgnc_Board[dgnc_NumBoards] =
476                 kzalloc(sizeof(*brd), GFP_KERNEL);
477         if (!brd)
478                 return -ENOMEM;
479 
480         /* make a temporary message buffer for the boot messages */
481         brd->msgbuf = brd->msgbuf_head =
482                 kzalloc(sizeof(u8) * 8192, GFP_KERNEL);
483         if (!brd->msgbuf) {
484                 kfree(brd);
485                 return -ENOMEM;
486         }
487 
488         /* store the info for the board we've found */
489         brd->magic = DGNC_BOARD_MAGIC;
490         brd->boardnum = dgnc_NumBoards;
491         brd->vendor = dgnc_pci_tbl[id].vendor;
492         brd->device = dgnc_pci_tbl[id].device;
493         brd->pdev = pdev;
494         brd->pci_bus = pdev->bus->number;
495         brd->pci_slot = PCI_SLOT(pdev->devfn);
496         brd->name = dgnc_Ids[id].name;
497         brd->maxports = dgnc_Ids[id].maxports;
498         if (dgnc_Ids[i].is_pci_express)
499                 brd->bd_flags |= BD_IS_PCI_EXPRESS;
500         brd->dpastatus = BD_NOFEP;
501         init_waitqueue_head(&brd->state_wait);
502 
503         DGNC_SPINLOCK_INIT(brd->bd_lock);
504         DGNC_SPINLOCK_INIT(brd->bd_intr_lock);
505 
506         brd->state              = BOARD_FOUND;
507 
508         for (i = 0; i < MAXPORTS; i++)
509                 brd->channels[i] = NULL;
510 
511         /* store which card & revision we have */
512         pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
513         pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
514         pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
515 
516         pci_irq = pdev->irq;
517         brd->irq = pci_irq;
518 
519 
520         switch (brd->device) {
521 
522         case PCI_DEVICE_CLASSIC_4_DID:
523         case PCI_DEVICE_CLASSIC_8_DID:
524         case PCI_DEVICE_CLASSIC_4_422_DID:
525         case PCI_DEVICE_CLASSIC_8_422_DID:
526 
527                 brd->dpatype = T_CLASSIC | T_PCIBUS;
528 
529                 DPR_INIT(("dgnc_found_board - Classic.\n"));
530 
531                 /*
532                  * For PCI ClassicBoards
533                  * PCI Local Address (i.e. "resource" number) space
534                  * 0    PLX Memory Mapped Config
535                  * 1    PLX I/O Mapped Config
536                  * 2    I/O Mapped UARTs and Status
537                  * 3    Memory Mapped VPD
538                  * 4    Memory Mapped UARTs and Status
539                  */
540 
541 
542                 /* get the PCI Base Address Registers */
543                 brd->membase = pci_resource_start(pdev, 4);
544 
545                 if (!brd->membase) {
546                         APR(("card has no PCI IO resources, failing board.\n"));
547                         return -ENODEV;
548                 }
549 
550                 brd->membase_end = pci_resource_end(pdev, 4);
551 
552                 if (brd->membase & 1)
553                         brd->membase &= ~3;
554                 else
555                         brd->membase &= ~15;
556 
557                 brd->iobase     = pci_resource_start(pdev, 1);
558                 brd->iobase_end = pci_resource_end(pdev, 1);
559                 brd->iobase     = ((unsigned int) (brd->iobase)) & 0xFFFE;
560 
561                 /* Assign the board_ops struct */
562                 brd->bd_ops = &dgnc_cls_ops;
563 
564                 brd->bd_uart_offset = 0x8;
565                 brd->bd_dividend = 921600;
566 
567                 dgnc_do_remap(brd);
568 
569                 /* Get and store the board VPD, if it exists */
570                 brd->bd_ops->vpd(brd);
571 
572                 /*
573                  * Enable Local Interrupt 1               (0x1),
574                  * Local Interrupt 1 Polarity Active high (0x2),
575                  * Enable PCI interrupt                   (0x40)
576                  */
577                 outb(0x43, brd->iobase + 0x4c);
578 
579                 break;
580 
581 
582         case PCI_DEVICE_NEO_4_DID:
583         case PCI_DEVICE_NEO_8_DID:
584         case PCI_DEVICE_NEO_2DB9_DID:
585         case PCI_DEVICE_NEO_2DB9PRI_DID:
586         case PCI_DEVICE_NEO_2RJ45_DID:
587         case PCI_DEVICE_NEO_2RJ45PRI_DID:
588         case PCI_DEVICE_NEO_1_422_DID:
589         case PCI_DEVICE_NEO_1_422_485_DID:
590         case PCI_DEVICE_NEO_2_422_485_DID:
591         case PCI_DEVICE_NEO_EXPRESS_8_DID:
592         case PCI_DEVICE_NEO_EXPRESS_4_DID:
593         case PCI_DEVICE_NEO_EXPRESS_4RJ45_DID:
594         case PCI_DEVICE_NEO_EXPRESS_8RJ45_DID:
595 
596                 /*
597                  * This chip is set up 100% when we get to it.
598                  * No need to enable global interrupts or anything.
599                  */
600                 if (brd->bd_flags & BD_IS_PCI_EXPRESS)
601                         brd->dpatype = T_NEO_EXPRESS | T_PCIBUS;
602                 else
603                         brd->dpatype = T_NEO | T_PCIBUS;
604 
605                 DPR_INIT(("dgnc_found_board - NEO.\n"));
606 
607                 /* get the PCI Base Address Registers */
608                 brd->membase     = pci_resource_start(pdev, 0);
609                 brd->membase_end = pci_resource_end(pdev, 0);
610 
611                 if (brd->membase & 1)
612                         brd->membase &= ~3;
613                 else
614                         brd->membase &= ~15;
615 
616                 /* Assign the board_ops struct */
617                 brd->bd_ops = &dgnc_neo_ops;
618 
619                 brd->bd_uart_offset = 0x200;
620                 brd->bd_dividend = 921600;
621 
622                 dgnc_do_remap(brd);
623 
624                 if (brd->re_map_membase) {
625 
626                         /* After remap is complete, we need to read and store the dvid */
627                         brd->dvid = readb(brd->re_map_membase + 0x8D);
628 
629                         /* Get and store the board VPD, if it exists */
630                         brd->bd_ops->vpd(brd);
631                 }
632                 break;
633 
634         default:
635                 APR(("Did not find any compatible Neo or Classic PCI boards in system.\n"));
636                 return -ENXIO;
637 
638         }
639 
640         /*
641          * Do tty device initialization.
642          */
643 
644         rc = dgnc_tty_register(brd);
645         if (rc < 0) {
646                 dgnc_tty_uninit(brd);
647                 APR(("Can't register tty devices (%d)\n", rc));
648                 brd->state = BOARD_FAILED;
649                 brd->dpastatus = BD_NOFEP;
650                 goto failed;
651         }
652 
653         rc = dgnc_finalize_board_init(brd);
654         if (rc < 0) {
655                 APR(("Can't finalize board init (%d)\n", rc));
656                 brd->state = BOARD_FAILED;
657                 brd->dpastatus = BD_NOFEP;
658 
659                 goto failed;
660         }
661 
662         rc = dgnc_tty_init(brd);
663         if (rc < 0) {
664                 dgnc_tty_uninit(brd);
665                 APR(("Can't init tty devices (%d)\n", rc));
666                 brd->state = BOARD_FAILED;
667                 brd->dpastatus = BD_NOFEP;
668 
669                 goto failed;
670         }
671 
672         brd->state = BOARD_READY;
673         brd->dpastatus = BD_RUNNING;
674 
675         dgnc_create_ports_sysfiles(brd);
676 
677         /* init our poll helper tasklet */
678         tasklet_init(&brd->helper_tasklet, brd->bd_ops->tasklet, (unsigned long) brd);
679 
680         DPR_INIT(("dgnc_scan(%d) - printing out the msgbuf\n", i));
681         DGNC_LOCK(dgnc_global_lock, flags);
682         brd->msgbuf = NULL;
683         printk("%s", brd->msgbuf_head);
684         kfree(brd->msgbuf_head);
685         brd->msgbuf_head = NULL;
686         DGNC_UNLOCK(dgnc_global_lock, flags);
687 
688         /*
689          * allocate flip buffer for board.
690          *
691          * Okay to malloc with GFP_KERNEL, we are not at interrupt
692          * context, and there are no locks held.
693          */
694         brd->flipbuf = kzalloc(MYFLIPLEN, GFP_KERNEL);
695 
696         wake_up_interruptible(&brd->state_wait);
697 
698         return 0;
699 
700 failed:
701 
702         return -ENXIO;
703 
704 }
705 
706 
707 static int dgnc_finalize_board_init(struct dgnc_board *brd)
708 {
709         int rc = 0;
710 
711         DPR_INIT(("dgnc_finalize_board_init() - start\n"));
712 
713         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
714                 return -ENODEV;
715 
716         DPR_INIT(("dgnc_finalize_board_init() - start #2\n"));
717 
718         if (brd->irq) {
719                 rc = request_irq(brd->irq, brd->bd_ops->intr,
720                                  IRQF_SHARED, "DGNC", brd);
721 
722                 if (rc) {
723                         dev_err(&brd->pdev->dev,
724                                 "Failed to hook IRQ %d\n", brd->irq);
725                         brd->state = BOARD_FAILED;
726                         brd->dpastatus = BD_NOFEP;
727                         rc = -ENODEV;
728                 } else {
729                         DPR_INIT(("Requested and received usage of IRQ %d\n",
730                                   brd->irq));
731                 }
732         }
733         return rc;
734 }
735 
736 /*
737  * Remap PCI memory.
738  */
739 static void dgnc_do_remap(struct dgnc_board *brd)
740 {
741 
742         if (!brd || brd->magic != DGNC_BOARD_MAGIC)
743                 return;
744 
745         brd->re_map_membase = ioremap(brd->membase, 0x1000);
746 
747         DPR_INIT(("remapped mem: 0x%p\n", brd->re_map_membase));
748 }
749 
750 
751 /*****************************************************************************
752 *
753 * Function:
754 *
755 *    dgnc_poll_handler
756 *
757 * Author:
758 *
759 *    Scott H Kilau
760 *
761 * Parameters:
762 *
763 *    dummy -- ignored
764 *
765 * Return Values:
766 *
767 *    none
768 *
769 * Description:
770 *
771 *    As each timer expires, it determines (a) whether the "transmit"
772 *    waiter needs to be woken up, and (b) whether the poller needs to
773 *    be rescheduled.
774 *
775 ******************************************************************************/
776 
777 static void dgnc_poll_handler(ulong dummy)
778 {
779         struct dgnc_board *brd;
780         unsigned long lock_flags;
781         int i;
782         unsigned long new_time;
783 
784         dgnc_poll_counter++;
785 
786         /*
787          * Do not start the board state machine until
788          * driver tells us its up and running, and has
789          * everything it needs.
790          */
791         if (dgnc_driver_state != DRIVER_READY)
792                 goto schedule_poller;
793 
794         /* Go thru each board, kicking off a tasklet for each if needed */
795         for (i = 0; i < dgnc_NumBoards; i++) {
796                 brd = dgnc_Board[i];
797 
798                 DGNC_LOCK(brd->bd_lock, lock_flags);
799 
800                 /* If board is in a failed state, don't bother scheduling a tasklet */
801                 if (brd->state == BOARD_FAILED) {
802                         DGNC_UNLOCK(brd->bd_lock, lock_flags);
803                         continue;
804                 }
805 
806                 /* Schedule a poll helper task */
807                 tasklet_schedule(&brd->helper_tasklet);
808 
809                 DGNC_UNLOCK(brd->bd_lock, lock_flags);
810         }
811 
812 schedule_poller:
813 
814         /*
815          * Schedule ourself back at the nominal wakeup interval.
816          */
817         DGNC_LOCK(dgnc_poll_lock, lock_flags);
818         dgnc_poll_time += dgnc_jiffies_from_ms(dgnc_poll_tick);
819 
820         new_time = dgnc_poll_time - jiffies;
821 
822         if ((ulong) new_time >= 2 * dgnc_poll_tick)
823                 dgnc_poll_time = jiffies +  dgnc_jiffies_from_ms(dgnc_poll_tick);
824 
825         init_timer(&dgnc_poll_timer);
826         dgnc_poll_timer.function = dgnc_poll_handler;
827         dgnc_poll_timer.data = 0;
828         dgnc_poll_timer.expires = dgnc_poll_time;
829         DGNC_UNLOCK(dgnc_poll_lock, lock_flags);
830 
831         if (!dgnc_poll_stop)
832                 add_timer(&dgnc_poll_timer);
833 }
834 
835 /*
836  * dgnc_init_globals()
837  *
838  * This is where we initialize the globals from the static insmod
839  * configuration variables.  These are declared near the head of
840  * this file.
841  */
842 static void dgnc_init_globals(void)
843 {
844         int i = 0;
845 
846         dgnc_rawreadok          = rawreadok;
847         dgnc_trcbuf_size        = trcbuf_size;
848         dgnc_debug              = debug;
849 
850         for (i = 0; i < MAXBOARDS; i++)
851                 dgnc_Board[i] = NULL;
852 
853         init_timer(&dgnc_poll_timer);
854 }
855 
856 
857 /************************************************************************
858  *
859  * Utility functions
860  *
861  ************************************************************************/
862 
863 /*
864  * dgnc_ms_sleep()
865  *
866  * Put the driver to sleep for x ms's
867  *
868  * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
869  */
870 int dgnc_ms_sleep(ulong ms)
871 {
872         current->state = TASK_INTERRUPTIBLE;
873         schedule_timeout((ms * HZ) / 1000);
874         return signal_pending(current);
875 }
876 
877 
878 
879 /*
880  *      dgnc_ioctl_name() : Returns a text version of each ioctl value.
881  */
882 char *dgnc_ioctl_name(int cmd)
883 {
884         switch (cmd) {
885 
886         case TCGETA:            return "TCGETA";
887         case TCGETS:            return "TCGETS";
888         case TCSETA:            return "TCSETA";
889         case TCSETS:            return "TCSETS";
890         case TCSETAW:           return "TCSETAW";
891         case TCSETSW:           return "TCSETSW";
892         case TCSETAF:           return "TCSETAF";
893         case TCSETSF:           return "TCSETSF";
894         case TCSBRK:            return "TCSBRK";
895         case TCXONC:            return "TCXONC";
896         case TCFLSH:            return "TCFLSH";
897         case TIOCGSID:          return "TIOCGSID";
898 
899         case TIOCGETD:          return "TIOCGETD";
900         case TIOCSETD:          return "TIOCSETD";
901         case TIOCGWINSZ:        return "TIOCGWINSZ";
902         case TIOCSWINSZ:        return "TIOCSWINSZ";
903 
904         case TIOCMGET:          return "TIOCMGET";
905         case TIOCMSET:          return "TIOCMSET";
906         case TIOCMBIS:          return "TIOCMBIS";
907         case TIOCMBIC:          return "TIOCMBIC";
908 
909         /* from digi.h */
910         case DIGI_SETA:         return "DIGI_SETA";
911         case DIGI_SETAW:        return "DIGI_SETAW";
912         case DIGI_SETAF:        return "DIGI_SETAF";
913         case DIGI_SETFLOW:      return "DIGI_SETFLOW";
914         case DIGI_SETAFLOW:     return "DIGI_SETAFLOW";
915         case DIGI_GETFLOW:      return "DIGI_GETFLOW";
916         case DIGI_GETAFLOW:     return "DIGI_GETAFLOW";
917         case DIGI_GETA:         return "DIGI_GETA";
918         case DIGI_GEDELAY:      return "DIGI_GEDELAY";
919         case DIGI_SEDELAY:      return "DIGI_SEDELAY";
920         case DIGI_GETCUSTOMBAUD: return "DIGI_GETCUSTOMBAUD";
921         case DIGI_SETCUSTOMBAUD: return "DIGI_SETCUSTOMBAUD";
922         case TIOCMODG:          return "TIOCMODG";
923         case TIOCMODS:          return "TIOCMODS";
924         case TIOCSDTR:          return "TIOCSDTR";
925         case TIOCCDTR:          return "TIOCCDTR";
926 
927         default:                return "unknown";
928         }
929 }
930 

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