Version:  2.0.40 2.2.26 2.4.37 3.0 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

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

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