[PATCH] g_file_storage: fix obscure race condition
[linux/fpc-iii.git] / drivers / isdn / sc / timer.c
blobaced19aac5a2e5011d81cb4f03ef6805836e5d62
1 /* $Id: timer.c,v 1.3.6.1 2001/09/23 22:24:59 kai Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
8 * For more information, please contact gpl-info@spellcast.com or write:
10 * SpellCaster Telecommunications Inc.
11 * 5621 Finch Avenue East, Unit #3
12 * Scarborough, Ontario Canada
13 * M1B 2T9
14 * +1 (416) 297-8565
15 * +1 (416) 297-6433 Facsimile
18 #include "includes.h"
19 #include "hardware.h"
20 #include "message.h"
21 #include "card.h"
23 extern board *sc_adapter[];
25 extern void flushreadfifo(int);
26 extern int startproc(int);
27 extern int indicate_status(int, int, unsigned long, char *);
28 extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
29 unsigned int, unsigned int, unsigned int, unsigned int *);
33 * Write the proper values into the I/O ports following a reset
35 static void setup_ports(int card)
38 outb((sc_adapter[card]->rambase >> 12), sc_adapter[card]->ioport[EXP_BASE]);
40 /* And the IRQ */
41 outb((sc_adapter[card]->interrupt | 0x80),
42 sc_adapter[card]->ioport[IRQ_SELECT]);
46 * Timed function to check the status of a previous reset
47 * Must be very fast as this function runs in the context of
48 * an interrupt handler.
50 * Setup the ioports for the board that were cleared by the reset.
51 * Then, check to see if the signate has been set. Next, set the
52 * signature to a known value and issue a startproc if needed.
54 void check_reset(unsigned long data)
56 unsigned long flags;
57 unsigned long sig;
58 int card = (unsigned int) data;
60 pr_debug("%s: check_timer timer called\n",
61 sc_adapter[card]->devicename);
63 /* Setup the io ports */
64 setup_ports(card);
66 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
67 outb(sc_adapter[card]->ioport[sc_adapter[card]->shmem_pgport],
68 (sc_adapter[card]->shmem_magic>>14) | 0x80);
69 sig = (unsigned long) *((unsigned long *)(sc_adapter[card]->rambase + SIG_OFFSET));
71 /* check the signature */
72 if(sig == SIGNATURE) {
73 flushreadfifo(card);
74 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
75 /* See if we need to do a startproc */
76 if (sc_adapter[card]->StartOnReset)
77 startproc(card);
78 } else {
79 pr_debug("%s: No signature yet, waiting another %d jiffies.\n",
80 sc_adapter[card]->devicename, CHECKRESET_TIME);
81 mod_timer(&sc_adapter[card]->reset_timer, jiffies+CHECKRESET_TIME);
82 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
87 * Timed function to check the status of a previous reset
88 * Must be very fast as this function runs in the context of
89 * an interrupt handler.
91 * Send check sc_adapter->phystat to see if the channels are up
92 * If they are, tell ISDN4Linux that the board is up. If not,
93 * tell IADN4Linux that it is up. Always reset the timer to
94 * fire again (endless loop).
96 void check_phystat(unsigned long data)
98 unsigned long flags;
99 int card = (unsigned int) data;
101 pr_debug("%s: Checking status...\n", sc_adapter[card]->devicename);
103 * check the results of the last PhyStat and change only if
104 * has changed drastically
106 if (sc_adapter[card]->nphystat && !sc_adapter[card]->phystat) { /* All is well */
107 pr_debug("PhyStat transition to RUN\n");
108 pr_info("%s: Switch contacted, transmitter enabled\n",
109 sc_adapter[card]->devicename);
110 indicate_status(card, ISDN_STAT_RUN, 0, NULL);
112 else if (!sc_adapter[card]->nphystat && sc_adapter[card]->phystat) { /* All is not well */
113 pr_debug("PhyStat transition to STOP\n");
114 pr_info("%s: Switch connection lost, transmitter disabled\n",
115 sc_adapter[card]->devicename);
117 indicate_status(card, ISDN_STAT_STOP, 0, NULL);
120 sc_adapter[card]->phystat = sc_adapter[card]->nphystat;
122 /* Reinitialize the timer */
123 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
124 mod_timer(&sc_adapter[card]->stat_timer, jiffies+CHECKSTAT_TIME);
125 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
127 /* Send a new cePhyStatus message */
128 sendmessage(card, CEPID,ceReqTypePhy,ceReqClass2,
129 ceReqPhyStatus,0,0,NULL);