2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
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)
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.
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.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
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.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
30 * $Id: dgap_driver.c,v 1.3 2011/06/21 10:35:16 markh Exp $
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/pci.h>
37 #include <linux/delay.h> /* For udelay */
38 #include <linux/slab.h>
39 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
40 #include <linux/sched.h>
42 #include "dgap_driver.h"
44 #include "dgap_fep5.h"
46 #include "dgap_conf.h"
47 #include "dgap_parse.h"
48 #include "dgap_trace.h"
49 #include "dgap_sysfs.h"
51 MODULE_LICENSE("GPL");
52 MODULE_AUTHOR("Digi International, http://www.digi.com");
53 MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
54 MODULE_SUPPORTED_DEVICE("dgap");
57 * insmod command line overrideable parameters
59 * NOTE: we use a set of macros to create the variables, which allows
60 * us to specify the variable type, name, initial value, and description.
62 PARM_INT(debug, 0x00, 0644, "Driver debugging level");
63 PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
64 PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
67 /**************************************************************************
69 * protos for this file
73 static int dgap_start(void);
74 static void dgap_init_globals(void);
75 static int dgap_found_board(struct pci_dev *pdev, int id);
76 static void dgap_cleanup_board(struct board_t *brd);
77 static void dgap_poll_handler(ulong dummy);
78 static int dgap_init_pci(void);
79 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
80 static void dgap_remove_one(struct pci_dev *dev);
81 static int dgap_probe1(struct pci_dev *pdev, int card_type);
82 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...);
83 static int dgap_do_remap(struct board_t *brd);
84 static irqreturn_t dgap_intr(int irq, void *voidbrd);
86 /* Driver load/unload functions */
87 int dgap_init_module(void);
88 void dgap_cleanup_module(void);
90 module_init(dgap_init_module);
91 module_exit(dgap_cleanup_module);
95 * File operations permitted on Control/Management major.
97 static struct file_operations DgapBoardFops =
107 struct board_t *dgap_Board[MAXBOARDS];
108 DEFINE_SPINLOCK(dgap_global_lock);
109 ulong dgap_poll_counter;
110 char *dgap_config_buf;
111 int dgap_driver_state = DRIVER_INITIALIZED;
112 DEFINE_SPINLOCK(dgap_dl_lock);
113 wait_queue_head_t dgap_dl_wait;
115 int dgap_poll_tick = 20; /* Poll interval - 20 ms */
120 static int dgap_Major_Control_Registered = FALSE;
121 static uint dgap_driver_start = FALSE;
123 static struct class * dgap_class;
128 static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
129 static ulong dgap_poll_time; /* Time of next poll */
130 static uint dgap_poll_stop; /* Used to tell poller to stop */
131 static struct timer_list dgap_poll_timer;
134 static struct pci_device_id dgap_pci_tbl[] = {
135 { DIGI_VID, PCI_DEVICE_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
136 { DIGI_VID, PCI_DEVICE_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
137 { DIGI_VID, PCI_DEVICE_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
138 { DIGI_VID, PCI_DEVICE_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
139 { DIGI_VID, PCI_DEVICE_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
140 { DIGI_VID, PCI_DEVICE_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
141 { DIGI_VID, PCI_DEVICE_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
142 { DIGI_VID, PCI_DEVICE_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
143 { DIGI_VID, PCI_DEVICE_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
144 { DIGI_VID, PCI_DEVICE_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
145 { DIGI_VID, PCI_DEVICE_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
146 { DIGI_VID, PCI_DEVICE_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
147 { DIGI_VID, PCI_DEVICE_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
148 { DIGI_VID, PCI_DEVICE_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
149 { DIGI_VID, PCI_DEVICE_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
150 {0,} /* 0 terminated list. */
152 MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
156 * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
165 static struct board_id dgap_Ids[] =
167 { PPCM, PCI_DEVICE_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
168 { PCX, PCI_DEVICE_CX_NAME, 128, (T_CX | T_PCIBUS) },
169 { PCX, PCI_DEVICE_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
170 { PEPC, PCI_DEVICE_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
171 { APORT2_920P, PCI_DEVICE_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS) },
172 { APORT4_920P, PCI_DEVICE_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS) },
173 { APORT8_920P, PCI_DEVICE_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
174 { PAPORT8, PCI_DEVICE_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
175 { PAPORT8, PCI_DEVICE_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
176 { PAPORT8, PCI_DEVICE_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
177 { PAPORT8, PCI_DEVICE_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
178 { PAPORT8, PCI_DEVICE_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
179 { PAPORT8, PCI_DEVICE_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
180 { APORT8_920P, PCI_DEVICE_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS) },
181 { PPCM, PCI_DEVICE_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS) },
182 {0,} /* 0 terminated list. */
185 static struct pci_driver dgap_driver = {
187 .probe = dgap_init_one,
188 .id_table = dgap_pci_tbl,
189 .remove = dgap_remove_one,
193 char *dgap_state_text[] = {
195 "Configuration for board not found.\n\t\t\tRun mpi to configure board.",
201 "Need Device Creation",
202 "Requested Device Creation",
203 "Finished Device Creation",
207 "Finished BIOS Load",
212 "Requested PROC creation",
213 "Finished PROC creation",
217 char *dgap_driver_state_text[] = {
218 "Driver Initialized",
219 "Driver needs configuration load.",
220 "Driver requested configuration from download daemon.",
226 /************************************************************************
228 * Driver load/unload functions
230 ************************************************************************/
235 * Module load. This is where it all starts.
237 int dgap_init_module(void)
241 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
244 * Initialize global stuff
253 * Find and configure all the cards
255 rc = dgap_init_pci();
258 * If something went wrong in the scan, bail out of driver.
261 /* Only unregister the pci driver if it was actually registered. */
263 pci_unregister_driver(&dgap_driver);
265 printk("WARNING: dgap driver load failed. No DGAP boards found.\n");
267 dgap_cleanup_module();
270 dgap_create_driver_sysfiles(&dgap_driver);
273 DPR_INIT(("Finished init_module. Returning %d\n", rc));
281 static int dgap_start(void)
286 if (dgap_driver_start == FALSE) {
288 dgap_driver_start = TRUE;
290 /* make sure that the globals are init'd before we do anything else */
295 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
298 * Register our base character device into the kernel.
299 * This allows the download daemon to connect to the downld device
300 * before any of the boards are init'ed.
302 if (!dgap_Major_Control_Registered) {
304 * Register management/dpa devices
306 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &DgapBoardFops);
308 APR(("Can't register dgap driver device (%d)\n", rc));
312 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
313 device_create(dgap_class, NULL,
314 MKDEV(DIGI_DGAP_MAJOR, 0),
316 device_create(dgap_class, NULL,
317 MKDEV(DIGI_DGAP_MAJOR, 1),
318 NULL, "dgap_downld");
319 dgap_Major_Control_Registered = TRUE;
323 * Init any global tty stuff.
325 rc = dgap_tty_preinit();
328 APR(("tty preinit - not enough memory (%d)\n", rc));
332 /* Start the poller */
333 DGAP_LOCK(dgap_poll_lock, flags);
334 init_timer(&dgap_poll_timer);
335 dgap_poll_timer.function = dgap_poll_handler;
336 dgap_poll_timer.data = 0;
337 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
338 dgap_poll_timer.expires = dgap_poll_time;
339 DGAP_UNLOCK(dgap_poll_lock, flags);
341 add_timer(&dgap_poll_timer);
343 dgap_driver_state = DRIVER_NEED_CONFIG_LOAD;
351 * Register pci driver, and return how many boards we have.
353 static int dgap_init_pci(void)
355 return pci_register_driver(&dgap_driver);
359 /* returns count (>= 0), or negative on error */
360 static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
364 /* wake up and enable device */
365 rc = pci_enable_device(pdev);
370 rc = dgap_probe1(pdev, ent->driver_data);
373 DPR_INIT(("Incrementing numboards to %d\n", dgap_NumBoards));
380 static int dgap_probe1(struct pci_dev *pdev, int card_type)
382 return dgap_found_board(pdev, card_type);
386 static void dgap_remove_one(struct pci_dev *dev)
393 * dgap_cleanup_module()
395 * Module unload. This is where it all ends.
397 void dgap_cleanup_module(void)
402 DGAP_LOCK(dgap_poll_lock, lock_flags);
404 DGAP_UNLOCK(dgap_poll_lock, lock_flags);
406 /* Turn off poller right away. */
407 del_timer_sync( &dgap_poll_timer);
409 dgap_remove_driver_sysfiles(&dgap_driver);
412 if (dgap_Major_Control_Registered) {
413 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
414 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 1));
415 class_destroy(dgap_class);
416 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
420 kfree(dgap_config_buf);
422 for (i = 0; i < dgap_NumBoards; ++i) {
423 dgap_remove_ports_sysfiles(dgap_Board[i]);
424 dgap_tty_uninit(dgap_Board[i]);
425 dgap_cleanup_board(dgap_Board[i]);
428 dgap_tty_post_uninit();
430 #if defined(DGAP_TRACER)
431 /* last thing, make sure we release the tracebuffer */
435 pci_unregister_driver(&dgap_driver);
440 * dgap_cleanup_board()
442 * Free all the memory associated with a board
444 static void dgap_cleanup_board(struct board_t *brd)
448 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
451 if (brd->intr_used && brd->irq)
452 free_irq(brd->irq, brd);
454 tasklet_kill(&brd->helper_tasklet);
456 if (brd->re_map_port) {
457 release_mem_region(brd->membase + 0x200000, 0x200000);
458 iounmap(brd->re_map_port);
459 brd->re_map_port = NULL;
462 if (brd->re_map_membase) {
463 release_mem_region(brd->membase, 0x200000);
464 iounmap(brd->re_map_membase);
465 brd->re_map_membase = NULL;
468 if (brd->msgbuf_head) {
471 DGAP_LOCK(dgap_global_lock, flags);
473 printk("%s", brd->msgbuf_head);
474 kfree(brd->msgbuf_head);
475 brd->msgbuf_head = NULL;
476 DGAP_UNLOCK(dgap_global_lock, flags);
479 /* Free all allocated channels structs */
480 for (i = 0; i < MAXPORTS ; i++) {
481 if (brd->channels[i]) {
482 kfree(brd->channels[i]);
483 brd->channels[i] = NULL;
489 if (brd->flipflagbuf)
490 kfree(brd->flipflagbuf);
492 dgap_Board[brd->boardnum] = NULL;
501 * A board has been found, init it.
503 static int dgap_found_board(struct pci_dev *pdev, int id)
506 unsigned int pci_irq;
510 /* get the board structure and prep it */
511 brd = dgap_Board[dgap_NumBoards] =
512 (struct board_t *) dgap_driver_kzmalloc(sizeof(struct board_t), GFP_KERNEL);
514 APR(("memory allocation for board structure failed\n"));
518 /* make a temporary message buffer for the boot messages */
519 brd->msgbuf = brd->msgbuf_head =
520 (char *) dgap_driver_kzmalloc(sizeof(char) * 8192, GFP_KERNEL);
523 APR(("memory allocation for board msgbuf failed\n"));
527 /* store the info for the board we've found */
528 brd->magic = DGAP_BOARD_MAGIC;
529 brd->boardnum = dgap_NumBoards;
531 brd->vendor = dgap_pci_tbl[id].vendor;
532 brd->device = dgap_pci_tbl[id].device;
534 brd->pci_bus = pdev->bus->number;
535 brd->pci_slot = PCI_SLOT(pdev->devfn);
536 brd->name = dgap_Ids[id].name;
537 brd->maxports = dgap_Ids[id].maxports;
538 brd->type = dgap_Ids[id].config_type;
539 brd->dpatype = dgap_Ids[id].dpatype;
540 brd->dpastatus = BD_NOFEP;
541 init_waitqueue_head(&brd->state_wait);
543 DGAP_SPINLOCK_INIT(brd->bd_lock);
545 brd->state = BOARD_FOUND;
547 brd->inhibit_poller = FALSE;
548 brd->wait_for_bios = 0;
549 brd->wait_for_fep = 0;
551 for (i = 0; i < MAXPORTS; i++) {
552 brd->channels[i] = NULL;
555 /* store which card & revision we have */
556 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
557 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
558 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
563 /* get the PCI Base Address Registers */
565 /* Xr Jupiter and EPC use BAR 2 */
566 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
567 brd->membase = pci_resource_start(pdev, 2);
568 brd->membase_end = pci_resource_end(pdev, 2);
570 /* Everyone else uses BAR 0 */
572 brd->membase = pci_resource_start(pdev, 0);
573 brd->membase_end = pci_resource_end(pdev, 0);
577 APR(("card has no PCI IO resources, failing board.\n"));
581 if (brd->membase & 1)
587 * On the PCI boards, there is no IO space allocated
588 * The I/O registers will be in the first 3 bytes of the
589 * upper 2MB of the 4MB memory space. The board memory
590 * will be mapped into the low 2MB of the 4MB memory space
592 brd->port = brd->membase + PCI_IO_OFFSET;
593 brd->port_end = brd->port + PCI_IO_SIZE;
597 * Special initialization for non-PLX boards
599 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
602 pci_write_config_byte(pdev, 0x40, 0);
603 pci_write_config_byte(pdev, 0x46, 0);
605 /* Limit burst length to 2 doubleword transactions */
606 pci_write_config_byte(pdev, 0x42, 1);
609 * Enable IO and mem if not already done.
610 * This was needed for support on Itanium.
612 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
613 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
614 pci_write_config_word(pdev, PCI_COMMAND, cmd);
617 /* init our poll helper tasklet */
618 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
620 /* Log the information about the board */
621 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
622 dgap_NumBoards, brd->name, brd->rev, brd->irq);
624 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
625 DGAP_LOCK(dgap_global_lock, flags);
627 printk("%s", brd->msgbuf_head);
628 kfree(brd->msgbuf_head);
629 brd->msgbuf_head = NULL;
630 DGAP_UNLOCK(dgap_global_lock, flags);
632 i = dgap_do_remap(brd);
634 brd->state = BOARD_FAILED;
636 brd->state = NEED_RESET;
642 int dgap_finalize_board_init(struct board_t *brd) {
646 DPR_INIT(("dgap_finalize_board_init() - start\n"));
648 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
651 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
653 brd->use_interrupts = dgap_config_get_useintr(brd);
656 * Set up our interrupt handler if we are set to do interrupts.
658 if (brd->use_interrupts && brd->irq) {
660 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
663 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
680 static int dgap_do_remap(struct board_t *brd)
682 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
685 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
686 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
690 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
691 APR(("dgap: mem_region IO %lx already in use.\n",
692 brd->membase + PCI_IO_OFFSET));
693 release_mem_region(brd->membase, 0x200000);
697 brd->re_map_membase = ioremap(brd->membase, 0x200000);
698 if (!brd->re_map_membase) {
699 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
700 release_mem_region(brd->membase, 0x200000);
701 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
705 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
706 if (!brd->re_map_port) {
707 release_mem_region(brd->membase, 0x200000);
708 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
709 iounmap(brd->re_map_membase);
710 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
711 brd->membase + PCI_IO_OFFSET));
715 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
716 brd->re_map_port, brd->re_map_membase));
721 /*****************************************************************************
741 * As each timer expires, it determines (a) whether the "transmit"
742 * waiter needs to be woken up, and (b) whether the poller needs to
745 ******************************************************************************/
747 static void dgap_poll_handler(ulong dummy)
751 unsigned long lock_flags;
752 unsigned long lock_flags2;
759 * If driver needs the config file still,
760 * keep trying to wake up the downloader to
763 if (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD) {
765 * Signal downloader, its got some work to do.
767 DGAP_LOCK(dgap_dl_lock, lock_flags2);
768 if (dgap_dl_action != 1) {
770 wake_up_interruptible(&dgap_dl_wait);
772 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
773 goto schedule_poller;
776 * Do not start the board state machine until
777 * driver tells us its up and running, and has
778 * everything it needs.
780 else if (dgap_driver_state != DRIVER_READY) {
781 goto schedule_poller;
785 * If we have just 1 board, or the system is not SMP,
786 * then use the typical old style poller.
787 * Otherwise, use our new tasklet based poller, which should
788 * speed things up for multiple boards.
790 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
791 for (i = 0; i < dgap_NumBoards; i++) {
795 if (brd->state == BOARD_FAILED) {
798 if (!brd->intr_running) {
799 /* Call the real board poller directly */
800 dgap_poll_tasklet((unsigned long) brd);
805 /* Go thru each board, kicking off a tasklet for each if needed */
806 for (i = 0; i < dgap_NumBoards; i++) {
810 * Attempt to grab the board lock.
812 * If we can't get it, no big deal, the next poll will get it.
813 * Basically, I just really don't want to spin in here, because I want
814 * to kick off my tasklets as fast as I can, and then get out the poller.
816 if (!spin_trylock(&brd->bd_lock)) {
820 /* If board is in a failed state, don't bother scheduling a tasklet */
821 if (brd->state == BOARD_FAILED) {
822 spin_unlock(&brd->bd_lock);
826 /* Schedule a poll helper task */
827 if (!brd->intr_running) {
828 tasklet_schedule(&brd->helper_tasklet);
832 * Can't do DGAP_UNLOCK here, as we don't have
833 * lock_flags because we did a trylock above.
835 spin_unlock(&brd->bd_lock);
842 * Schedule ourself back at the nominal wakeup interval.
844 DGAP_LOCK(dgap_poll_lock, lock_flags );
845 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
847 new_time = dgap_poll_time - jiffies;
849 if ((ulong) new_time >= 2 * dgap_poll_tick) {
850 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
853 dgap_poll_timer.function = dgap_poll_handler;
854 dgap_poll_timer.data = 0;
855 dgap_poll_timer.expires = dgap_poll_time;
856 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
859 add_timer(&dgap_poll_timer);
868 * Driver interrupt handler.
870 static irqreturn_t dgap_intr(int irq, void *voidbrd)
872 struct board_t *brd = (struct board_t *) voidbrd;
875 APR(("Received interrupt (%d) with null board associated\n", irq));
880 * Check to make sure its for us.
882 if (brd->magic != DGAP_BOARD_MAGIC) {
883 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
890 * Schedule tasklet to run at a better time.
892 tasklet_schedule(&brd->helper_tasklet);
898 * dgap_init_globals()
900 * This is where we initialize the globals from the static insmod
901 * configuration variables. These are declared near the head of
904 static void dgap_init_globals(void)
908 dgap_rawreadok = rawreadok;
909 dgap_trcbuf_size = trcbuf_size;
912 for (i = 0; i < MAXBOARDS; i++) {
913 dgap_Board[i] = NULL;
916 init_timer( &dgap_poll_timer );
918 init_waitqueue_head(&dgap_dl_wait);
923 /************************************************************************
927 ************************************************************************/
931 * dgap_driver_kzmalloc()
933 * Malloc and clear memory,
935 void *dgap_driver_kzmalloc(size_t size, int priority)
937 void *p = kmalloc(size, priority);
947 * Used to print to the message buffer during board init.
949 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
956 DGAP_LOCK(dgap_global_lock, flags);
958 /* Format buf using fmt and arguments contained in ap. */
960 i = vsnprintf(buf, sizeof(buf), fmt, ap);
965 if (!brd || !brd->msgbuf) {
967 DGAP_UNLOCK(dgap_global_lock, flags);
971 length = strlen(buf) + 1;
972 if (brd->msgbuf - brd->msgbuf_head < length)
973 length = brd->msgbuf - brd->msgbuf_head;
974 memcpy(brd->msgbuf, buf, length);
975 brd->msgbuf += length;
977 DGAP_UNLOCK(dgap_global_lock, flags);
984 * Put the driver to sleep for x ms's
986 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
988 int dgap_ms_sleep(ulong ms)
990 current->state = TASK_INTERRUPTIBLE;
991 schedule_timeout((ms * HZ) / 1000);
992 return (signal_pending(current));
998 * dgap_ioctl_name() : Returns a text version of each ioctl value.
1000 char *dgap_ioctl_name(int cmd)
1004 case TCGETA: return("TCGETA");
1005 case TCGETS: return("TCGETS");
1006 case TCSETA: return("TCSETA");
1007 case TCSETS: return("TCSETS");
1008 case TCSETAW: return("TCSETAW");
1009 case TCSETSW: return("TCSETSW");
1010 case TCSETAF: return("TCSETAF");
1011 case TCSETSF: return("TCSETSF");
1012 case TCSBRK: return("TCSBRK");
1013 case TCXONC: return("TCXONC");
1014 case TCFLSH: return("TCFLSH");
1015 case TIOCGSID: return("TIOCGSID");
1017 case TIOCGETD: return("TIOCGETD");
1018 case TIOCSETD: return("TIOCSETD");
1019 case TIOCGWINSZ: return("TIOCGWINSZ");
1020 case TIOCSWINSZ: return("TIOCSWINSZ");
1022 case TIOCMGET: return("TIOCMGET");
1023 case TIOCMSET: return("TIOCMSET");
1024 case TIOCMBIS: return("TIOCMBIS");
1025 case TIOCMBIC: return("TIOCMBIC");
1028 case DIGI_SETA: return("DIGI_SETA");
1029 case DIGI_SETAW: return("DIGI_SETAW");
1030 case DIGI_SETAF: return("DIGI_SETAF");
1031 case DIGI_SETFLOW: return("DIGI_SETFLOW");
1032 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
1033 case DIGI_GETFLOW: return("DIGI_GETFLOW");
1034 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
1035 case DIGI_GETA: return("DIGI_GETA");
1036 case DIGI_GEDELAY: return("DIGI_GEDELAY");
1037 case DIGI_SEDELAY: return("DIGI_SEDELAY");
1038 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
1039 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
1040 case TIOCMODG: return("TIOCMODG");
1041 case TIOCMODS: return("TIOCMODS");
1042 case TIOCSDTR: return("TIOCSDTR");
1043 case TIOCCDTR: return("TIOCCDTR");
1045 default: return("unknown");