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

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

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