1 /* $Id: hysdn_sched.c,v 1.5.6.4 2001/11/06 21:58:19 kai Exp $
3 * Linux driver for HYSDN cards
4 * scheduler routines for handling exchange card <-> pc.
6 * Author Werner Cornelius (werner@titro.de) for Hypercope GmbH
7 * Copyright 1999 by Werner Cornelius (werner@titro.de)
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
14 #include <linux/config.h>
15 #include <linux/sched.h>
16 #include <linux/signal.h>
17 #include <linux/kernel.h>
18 #include <linux/ioport.h>
19 #include <linux/interrupt.h>
22 #include "hysdn_defs.h"
24 /*****************************************************************************/
25 /* hysdn_sched_rx is called from the cards handler to announce new data is */
26 /* available from the card. The routine has to handle the data and return */
27 /* with a nonzero code if the data could be worked (or even thrown away), if */
28 /* no room to buffer the data is available a zero return tells the card */
29 /* to keep the data until later. */
30 /*****************************************************************************/
32 hysdn_sched_rx(hysdn_card * card, uchar * buf, word len, word chan)
37 if (hynet_enable & (1 << card->myid)) {
38 /* give packet to network handler */
39 hysdn_rx_netpkt(card, buf, len);
44 hysdn_card_errlog(card, (tErrLogEntry *) buf, len);
45 if (card->err_log_state == ERRLOG_STATE_ON)
46 card->err_log_state = ERRLOG_STATE_START; /* start new fetch */
48 #ifdef CONFIG_HYSDN_CAPI
50 /* give packet to CAPI handler */
51 if (hycapi_enable & (1 << card->myid)) {
52 hycapi_rx_capipkt(card, buf, len);
55 #endif /* CONFIG_HYSDN_CAPI */
57 printk(KERN_INFO "irq message channel %d len %d unhandled \n", chan, len);
60 } /* switch rx channel */
62 return (1); /* always handled */
63 } /* hysdn_sched_rx */
65 /*****************************************************************************/
66 /* hysdn_sched_tx is called from the cards handler to announce that there is */
67 /* room in the tx-buffer to the card and data may be sent if needed. */
68 /* If the routine wants to send data it must fill buf, len and chan with the */
69 /* appropriate data and return a nonzero value. With a zero return no new */
70 /* data to send is assumed. maxlen specifies the buffer size available for */
72 /*****************************************************************************/
74 hysdn_sched_tx(hysdn_card * card, uchar * buf, word volatile *len, word volatile *chan, word maxlen)
78 if (card->net_tx_busy) {
79 card->net_tx_busy = 0; /* reset flag */
80 hysdn_tx_netack(card); /* acknowledge packet send */
81 } /* a network packet has completely been transferred */
82 /* first of all async requests are handled */
83 if (card->async_busy) {
84 if (card->async_len <= maxlen) {
85 memcpy(buf, card->async_data, card->async_len);
86 *len = card->async_len;
87 *chan = card->async_channel;
88 card->async_busy = 0; /* reset request */
91 card->async_busy = 0; /* in case of length error */
93 if ((card->err_log_state == ERRLOG_STATE_START) &&
94 (maxlen >= ERRLOG_CMD_REQ_SIZE)) {
95 strcpy(buf, ERRLOG_CMD_REQ); /* copy the command */
96 *len = ERRLOG_CMD_REQ_SIZE; /* buffer length */
97 *chan = CHAN_ERRLOG; /* and channel */
98 card->err_log_state = ERRLOG_STATE_ON; /* new state is on */
99 return (1); /* tell that data should be send */
100 } /* error log start and able to send */
101 if ((card->err_log_state == ERRLOG_STATE_STOP) &&
102 (maxlen >= ERRLOG_CMD_STOP_SIZE)) {
103 strcpy(buf, ERRLOG_CMD_STOP); /* copy the command */
104 *len = ERRLOG_CMD_STOP_SIZE; /* buffer length */
105 *chan = CHAN_ERRLOG; /* and channel */
106 card->err_log_state = ERRLOG_STATE_OFF; /* new state is off */
107 return (1); /* tell that data should be send */
108 } /* error log start and able to send */
109 /* now handle network interface packets */
110 if ((hynet_enable & (1 << card->myid)) &&
111 (skb = hysdn_tx_netget(card)) != NULL)
113 if (skb->len <= maxlen) {
114 memcpy(buf, skb->data, skb->len); /* copy the packet to the buffer */
116 *chan = CHAN_NDIS_DATA;
117 card->net_tx_busy = 1; /* we are busy sending network data */
118 return (1); /* go and send the data */
120 hysdn_tx_netack(card); /* aknowledge packet -> throw away */
121 } /* send a network packet if available */
122 #ifdef CONFIG_HYSDN_CAPI
123 if( ((hycapi_enable & (1 << card->myid))) &&
124 ((skb = hycapi_tx_capiget(card)) != NULL) )
126 if (skb->len <= maxlen) {
127 memcpy(buf, skb->data, skb->len);
130 hycapi_tx_capiack(card);
131 return (1); /* go and send the data */
134 #endif /* CONFIG_HYSDN_CAPI */
135 return (0); /* nothing to send */
136 } /* hysdn_sched_tx */
139 /*****************************************************************************/
140 /* send one config line to the card and return 0 if successful, otherwise a */
141 /* negative error code. */
142 /* The function works with timeouts perhaps not giving the greatest speed */
143 /* sending the line, but this should be meaningless beacuse only some lines */
144 /* are to be sent and this happens very seldom. */
145 /*****************************************************************************/
147 hysdn_tx_cfgline(hysdn_card * card, uchar * line, word chan)
149 int cnt = 50; /* timeout intervalls */
152 if (card->debug_flags & LOG_SCHED_ASYN)
153 hysdn_addlog(card, "async tx-cfg chan=%d len=%d", chan, strlen(line) + 1);
157 while (card->async_busy) {
160 if (card->debug_flags & LOG_SCHED_ASYN)
161 hysdn_addlog(card, "async tx-cfg delayed");
163 set_current_state(TASK_INTERRUPTIBLE);
164 schedule_timeout((20 * HZ) / 1000); /* Timeout 20ms */
166 restore_flags(flags);
167 return (-ERR_ASYNC_TIME); /* timed out */
170 } /* wait for buffer to become free */
172 strcpy(card->async_data, line);
173 card->async_len = strlen(line) + 1;
174 card->async_channel = chan;
175 card->async_busy = 1; /* request transfer */
177 /* now queue the task */
178 schedule_work(&card->irq_queue);
181 if (card->debug_flags & LOG_SCHED_ASYN)
182 hysdn_addlog(card, "async tx-cfg data queued");
184 cnt++; /* short delay */
187 while (card->async_busy) {
190 if (card->debug_flags & LOG_SCHED_ASYN)
191 hysdn_addlog(card, "async tx-cfg waiting for tx-ready");
193 set_current_state(TASK_INTERRUPTIBLE);
194 schedule_timeout((20 * HZ) / 1000); /* Timeout 20ms */
196 restore_flags(flags);
197 return (-ERR_ASYNC_TIME); /* timed out */
200 } /* wait for buffer to become free again */
202 restore_flags(flags);
204 if (card->debug_flags & LOG_SCHED_ASYN)
205 hysdn_addlog(card, "async tx-cfg data send");
207 return (0); /* line send correctly */
208 } /* hysdn_tx_cfgline */