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");
419 kfree(dgap_config_buf);
421 for (i = 0; i < dgap_NumBoards; ++i) {
422 dgap_remove_ports_sysfiles(dgap_Board[i]);
423 dgap_tty_uninit(dgap_Board[i]);
424 dgap_cleanup_board(dgap_Board[i]);
427 dgap_tty_post_uninit();
429 #if defined(DGAP_TRACER)
430 /* last thing, make sure we release the tracebuffer */
434 pci_unregister_driver(&dgap_driver);
439 * dgap_cleanup_board()
441 * Free all the memory associated with a board
443 static void dgap_cleanup_board(struct board_t *brd)
447 if(!brd || brd->magic != DGAP_BOARD_MAGIC)
450 if (brd->intr_used && brd->irq)
451 free_irq(brd->irq, brd);
453 tasklet_kill(&brd->helper_tasklet);
455 if (brd->re_map_port) {
456 release_mem_region(brd->membase + 0x200000, 0x200000);
457 iounmap(brd->re_map_port);
458 brd->re_map_port = NULL;
461 if (brd->re_map_membase) {
462 release_mem_region(brd->membase, 0x200000);
463 iounmap(brd->re_map_membase);
464 brd->re_map_membase = NULL;
467 if (brd->msgbuf_head) {
470 DGAP_LOCK(dgap_global_lock, flags);
472 printk("%s", brd->msgbuf_head);
473 kfree(brd->msgbuf_head);
474 brd->msgbuf_head = NULL;
475 DGAP_UNLOCK(dgap_global_lock, flags);
478 /* Free all allocated channels structs */
479 for (i = 0; i < MAXPORTS ; i++) {
480 if (brd->channels[i]) {
481 kfree(brd->channels[i]);
482 brd->channels[i] = NULL;
487 kfree(brd->flipflagbuf);
489 dgap_Board[brd->boardnum] = NULL;
498 * A board has been found, init it.
500 static int dgap_found_board(struct pci_dev *pdev, int id)
503 unsigned int pci_irq;
507 /* get the board structure and prep it */
508 brd = dgap_Board[dgap_NumBoards] =
509 (struct board_t *) dgap_driver_kzmalloc(sizeof(struct board_t), GFP_KERNEL);
511 APR(("memory allocation for board structure failed\n"));
515 /* make a temporary message buffer for the boot messages */
516 brd->msgbuf = brd->msgbuf_head =
517 (char *) dgap_driver_kzmalloc(sizeof(char) * 8192, GFP_KERNEL);
520 APR(("memory allocation for board msgbuf failed\n"));
524 /* store the info for the board we've found */
525 brd->magic = DGAP_BOARD_MAGIC;
526 brd->boardnum = dgap_NumBoards;
528 brd->vendor = dgap_pci_tbl[id].vendor;
529 brd->device = dgap_pci_tbl[id].device;
531 brd->pci_bus = pdev->bus->number;
532 brd->pci_slot = PCI_SLOT(pdev->devfn);
533 brd->name = dgap_Ids[id].name;
534 brd->maxports = dgap_Ids[id].maxports;
535 brd->type = dgap_Ids[id].config_type;
536 brd->dpatype = dgap_Ids[id].dpatype;
537 brd->dpastatus = BD_NOFEP;
538 init_waitqueue_head(&brd->state_wait);
540 DGAP_SPINLOCK_INIT(brd->bd_lock);
542 brd->state = BOARD_FOUND;
544 brd->inhibit_poller = FALSE;
545 brd->wait_for_bios = 0;
546 brd->wait_for_fep = 0;
548 for (i = 0; i < MAXPORTS; i++) {
549 brd->channels[i] = NULL;
552 /* store which card & revision we have */
553 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
554 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
555 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
560 /* get the PCI Base Address Registers */
562 /* Xr Jupiter and EPC use BAR 2 */
563 if (brd->device == PCI_DEVICE_XRJ_DID || brd->device == PCI_DEVICE_EPCJ_DID) {
564 brd->membase = pci_resource_start(pdev, 2);
565 brd->membase_end = pci_resource_end(pdev, 2);
567 /* Everyone else uses BAR 0 */
569 brd->membase = pci_resource_start(pdev, 0);
570 brd->membase_end = pci_resource_end(pdev, 0);
574 APR(("card has no PCI IO resources, failing board.\n"));
578 if (brd->membase & 1)
584 * On the PCI boards, there is no IO space allocated
585 * The I/O registers will be in the first 3 bytes of the
586 * upper 2MB of the 4MB memory space. The board memory
587 * will be mapped into the low 2MB of the 4MB memory space
589 brd->port = brd->membase + PCI_IO_OFFSET;
590 brd->port_end = brd->port + PCI_IO_SIZE;
594 * Special initialization for non-PLX boards
596 if (brd->device != PCI_DEVICE_XRJ_DID && brd->device != PCI_DEVICE_EPCJ_DID) {
599 pci_write_config_byte(pdev, 0x40, 0);
600 pci_write_config_byte(pdev, 0x46, 0);
602 /* Limit burst length to 2 doubleword transactions */
603 pci_write_config_byte(pdev, 0x42, 1);
606 * Enable IO and mem if not already done.
607 * This was needed for support on Itanium.
609 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
610 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
611 pci_write_config_word(pdev, PCI_COMMAND, cmd);
614 /* init our poll helper tasklet */
615 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, (unsigned long) brd);
617 /* Log the information about the board */
618 dgap_mbuf(brd, DRVSTR": board %d: %s (rev %d), irq %d\n",
619 dgap_NumBoards, brd->name, brd->rev, brd->irq);
621 DPR_INIT(("dgap_scan(%d) - printing out the msgbuf\n", i));
622 DGAP_LOCK(dgap_global_lock, flags);
624 printk("%s", brd->msgbuf_head);
625 kfree(brd->msgbuf_head);
626 brd->msgbuf_head = NULL;
627 DGAP_UNLOCK(dgap_global_lock, flags);
629 i = dgap_do_remap(brd);
631 brd->state = BOARD_FAILED;
633 brd->state = NEED_RESET;
639 int dgap_finalize_board_init(struct board_t *brd) {
643 DPR_INIT(("dgap_finalize_board_init() - start\n"));
645 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
648 DPR_INIT(("dgap_finalize_board_init() - start #2\n"));
650 brd->use_interrupts = dgap_config_get_useintr(brd);
653 * Set up our interrupt handler if we are set to do interrupts.
655 if (brd->use_interrupts && brd->irq) {
657 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
660 dgap_mbuf(brd, DRVSTR": Failed to hook IRQ %d. Board will work in poll mode.\n",
677 static int dgap_do_remap(struct board_t *brd)
679 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
682 if (!request_mem_region(brd->membase, 0x200000, "dgap")) {
683 APR(("dgap: mem_region %lx already in use.\n", brd->membase));
687 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap")) {
688 APR(("dgap: mem_region IO %lx already in use.\n",
689 brd->membase + PCI_IO_OFFSET));
690 release_mem_region(brd->membase, 0x200000);
694 brd->re_map_membase = ioremap(brd->membase, 0x200000);
695 if (!brd->re_map_membase) {
696 APR(("dgap: ioremap mem %lx cannot be mapped.\n", brd->membase));
697 release_mem_region(brd->membase, 0x200000);
698 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
702 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
703 if (!brd->re_map_port) {
704 release_mem_region(brd->membase, 0x200000);
705 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
706 iounmap(brd->re_map_membase);
707 APR(("dgap: ioremap IO mem %lx cannot be mapped.\n",
708 brd->membase + PCI_IO_OFFSET));
712 DPR_INIT(("remapped io: 0x%p remapped mem: 0x%p\n",
713 brd->re_map_port, brd->re_map_membase));
718 /*****************************************************************************
738 * As each timer expires, it determines (a) whether the "transmit"
739 * waiter needs to be woken up, and (b) whether the poller needs to
742 ******************************************************************************/
744 static void dgap_poll_handler(ulong dummy)
748 unsigned long lock_flags;
749 unsigned long lock_flags2;
756 * If driver needs the config file still,
757 * keep trying to wake up the downloader to
760 if (dgap_driver_state == DRIVER_NEED_CONFIG_LOAD) {
762 * Signal downloader, its got some work to do.
764 DGAP_LOCK(dgap_dl_lock, lock_flags2);
765 if (dgap_dl_action != 1) {
767 wake_up_interruptible(&dgap_dl_wait);
769 DGAP_UNLOCK(dgap_dl_lock, lock_flags2);
770 goto schedule_poller;
773 * Do not start the board state machine until
774 * driver tells us its up and running, and has
775 * everything it needs.
777 else if (dgap_driver_state != DRIVER_READY) {
778 goto schedule_poller;
782 * If we have just 1 board, or the system is not SMP,
783 * then use the typical old style poller.
784 * Otherwise, use our new tasklet based poller, which should
785 * speed things up for multiple boards.
787 if ( (dgap_NumBoards == 1) || (num_online_cpus() <= 1) ) {
788 for (i = 0; i < dgap_NumBoards; i++) {
792 if (brd->state == BOARD_FAILED) {
795 if (!brd->intr_running) {
796 /* Call the real board poller directly */
797 dgap_poll_tasklet((unsigned long) brd);
802 /* Go thru each board, kicking off a tasklet for each if needed */
803 for (i = 0; i < dgap_NumBoards; i++) {
807 * Attempt to grab the board lock.
809 * If we can't get it, no big deal, the next poll will get it.
810 * Basically, I just really don't want to spin in here, because I want
811 * to kick off my tasklets as fast as I can, and then get out the poller.
813 if (!spin_trylock(&brd->bd_lock)) {
817 /* If board is in a failed state, don't bother scheduling a tasklet */
818 if (brd->state == BOARD_FAILED) {
819 spin_unlock(&brd->bd_lock);
823 /* Schedule a poll helper task */
824 if (!brd->intr_running) {
825 tasklet_schedule(&brd->helper_tasklet);
829 * Can't do DGAP_UNLOCK here, as we don't have
830 * lock_flags because we did a trylock above.
832 spin_unlock(&brd->bd_lock);
839 * Schedule ourself back at the nominal wakeup interval.
841 DGAP_LOCK(dgap_poll_lock, lock_flags );
842 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
844 new_time = dgap_poll_time - jiffies;
846 if ((ulong) new_time >= 2 * dgap_poll_tick) {
847 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
850 dgap_poll_timer.function = dgap_poll_handler;
851 dgap_poll_timer.data = 0;
852 dgap_poll_timer.expires = dgap_poll_time;
853 DGAP_UNLOCK(dgap_poll_lock, lock_flags );
856 add_timer(&dgap_poll_timer);
865 * Driver interrupt handler.
867 static irqreturn_t dgap_intr(int irq, void *voidbrd)
869 struct board_t *brd = (struct board_t *) voidbrd;
872 APR(("Received interrupt (%d) with null board associated\n", irq));
877 * Check to make sure its for us.
879 if (brd->magic != DGAP_BOARD_MAGIC) {
880 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
887 * Schedule tasklet to run at a better time.
889 tasklet_schedule(&brd->helper_tasklet);
895 * dgap_init_globals()
897 * This is where we initialize the globals from the static insmod
898 * configuration variables. These are declared near the head of
901 static void dgap_init_globals(void)
905 dgap_rawreadok = rawreadok;
906 dgap_trcbuf_size = trcbuf_size;
909 for (i = 0; i < MAXBOARDS; i++) {
910 dgap_Board[i] = NULL;
913 init_timer( &dgap_poll_timer );
915 init_waitqueue_head(&dgap_dl_wait);
920 /************************************************************************
924 ************************************************************************/
928 * dgap_driver_kzmalloc()
930 * Malloc and clear memory,
932 void *dgap_driver_kzmalloc(size_t size, int priority)
934 void *p = kmalloc(size, priority);
944 * Used to print to the message buffer during board init.
946 static void dgap_mbuf(struct board_t *brd, const char *fmt, ...) {
953 DGAP_LOCK(dgap_global_lock, flags);
955 /* Format buf using fmt and arguments contained in ap. */
957 i = vsnprintf(buf, sizeof(buf), fmt, ap);
962 if (!brd || !brd->msgbuf) {
964 DGAP_UNLOCK(dgap_global_lock, flags);
968 length = strlen(buf) + 1;
969 if (brd->msgbuf - brd->msgbuf_head < length)
970 length = brd->msgbuf - brd->msgbuf_head;
971 memcpy(brd->msgbuf, buf, length);
972 brd->msgbuf += length;
974 DGAP_UNLOCK(dgap_global_lock, flags);
981 * Put the driver to sleep for x ms's
983 * Returns 0 if timed out, !0 (showing signal) if interrupted by a signal.
985 int dgap_ms_sleep(ulong ms)
987 current->state = TASK_INTERRUPTIBLE;
988 schedule_timeout((ms * HZ) / 1000);
989 return (signal_pending(current));
995 * dgap_ioctl_name() : Returns a text version of each ioctl value.
997 char *dgap_ioctl_name(int cmd)
1001 case TCGETA: return("TCGETA");
1002 case TCGETS: return("TCGETS");
1003 case TCSETA: return("TCSETA");
1004 case TCSETS: return("TCSETS");
1005 case TCSETAW: return("TCSETAW");
1006 case TCSETSW: return("TCSETSW");
1007 case TCSETAF: return("TCSETAF");
1008 case TCSETSF: return("TCSETSF");
1009 case TCSBRK: return("TCSBRK");
1010 case TCXONC: return("TCXONC");
1011 case TCFLSH: return("TCFLSH");
1012 case TIOCGSID: return("TIOCGSID");
1014 case TIOCGETD: return("TIOCGETD");
1015 case TIOCSETD: return("TIOCSETD");
1016 case TIOCGWINSZ: return("TIOCGWINSZ");
1017 case TIOCSWINSZ: return("TIOCSWINSZ");
1019 case TIOCMGET: return("TIOCMGET");
1020 case TIOCMSET: return("TIOCMSET");
1021 case TIOCMBIS: return("TIOCMBIS");
1022 case TIOCMBIC: return("TIOCMBIC");
1025 case DIGI_SETA: return("DIGI_SETA");
1026 case DIGI_SETAW: return("DIGI_SETAW");
1027 case DIGI_SETAF: return("DIGI_SETAF");
1028 case DIGI_SETFLOW: return("DIGI_SETFLOW");
1029 case DIGI_SETAFLOW: return("DIGI_SETAFLOW");
1030 case DIGI_GETFLOW: return("DIGI_GETFLOW");
1031 case DIGI_GETAFLOW: return("DIGI_GETAFLOW");
1032 case DIGI_GETA: return("DIGI_GETA");
1033 case DIGI_GEDELAY: return("DIGI_GEDELAY");
1034 case DIGI_SEDELAY: return("DIGI_SEDELAY");
1035 case DIGI_GETCUSTOMBAUD: return("DIGI_GETCUSTOMBAUD");
1036 case DIGI_SETCUSTOMBAUD: return("DIGI_SETCUSTOMBAUD");
1037 case TIOCMODG: return("TIOCMODG");
1038 case TIOCMODS: return("TIOCMODS");
1039 case TIOCSDTR: return("TIOCSDTR");
1040 case TIOCCDTR: return("TIOCCDTR");
1042 default: return("unknown");