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>
20 #include <linux/delay.h>
23 #include "hysdn_defs.h"
25 /*****************************************************************************/
26 /* hysdn_sched_rx is called from the cards handler to announce new data is */
27 /* available from the card. The routine has to handle the data and return */
28 /* with a nonzero code if the data could be worked (or even thrown away), if */
29 /* no room to buffer the data is available a zero return tells the card */
30 /* to keep the data until later. */
31 /*****************************************************************************/
33 hysdn_sched_rx(hysdn_card
*card
, unsigned char *buf
, unsigned short len
,
39 if (hynet_enable
& (1 << card
->myid
)) {
40 /* give packet to network handler */
41 hysdn_rx_netpkt(card
, buf
, len
);
46 hysdn_card_errlog(card
, (tErrLogEntry
*) buf
, len
);
47 if (card
->err_log_state
== ERRLOG_STATE_ON
)
48 card
->err_log_state
= ERRLOG_STATE_START
; /* start new fetch */
50 #ifdef CONFIG_HYSDN_CAPI
52 /* give packet to CAPI handler */
53 if (hycapi_enable
& (1 << card
->myid
)) {
54 hycapi_rx_capipkt(card
, buf
, len
);
57 #endif /* CONFIG_HYSDN_CAPI */
59 printk(KERN_INFO
"irq message channel %d len %d unhandled \n", chan
, len
);
62 } /* switch rx channel */
64 return (1); /* always handled */
65 } /* hysdn_sched_rx */
67 /*****************************************************************************/
68 /* hysdn_sched_tx is called from the cards handler to announce that there is */
69 /* room in the tx-buffer to the card and data may be sent if needed. */
70 /* If the routine wants to send data it must fill buf, len and chan with the */
71 /* appropriate data and return a nonzero value. With a zero return no new */
72 /* data to send is assumed. maxlen specifies the buffer size available for */
74 /*****************************************************************************/
76 hysdn_sched_tx(hysdn_card
*card
, unsigned char *buf
,
77 unsigned short volatile *len
, unsigned short volatile *chan
,
78 unsigned short maxlen
)
82 if (card
->net_tx_busy
) {
83 card
->net_tx_busy
= 0; /* reset flag */
84 hysdn_tx_netack(card
); /* acknowledge packet send */
85 } /* a network packet has completely been transferred */
86 /* first of all async requests are handled */
87 if (card
->async_busy
) {
88 if (card
->async_len
<= maxlen
) {
89 memcpy(buf
, card
->async_data
, card
->async_len
);
90 *len
= card
->async_len
;
91 *chan
= card
->async_channel
;
92 card
->async_busy
= 0; /* reset request */
95 card
->async_busy
= 0; /* in case of length error */
97 if ((card
->err_log_state
== ERRLOG_STATE_START
) &&
98 (maxlen
>= ERRLOG_CMD_REQ_SIZE
)) {
99 strcpy(buf
, ERRLOG_CMD_REQ
); /* copy the command */
100 *len
= ERRLOG_CMD_REQ_SIZE
; /* buffer length */
101 *chan
= CHAN_ERRLOG
; /* and channel */
102 card
->err_log_state
= ERRLOG_STATE_ON
; /* new state is on */
103 return (1); /* tell that data should be send */
104 } /* error log start and able to send */
105 if ((card
->err_log_state
== ERRLOG_STATE_STOP
) &&
106 (maxlen
>= ERRLOG_CMD_STOP_SIZE
)) {
107 strcpy(buf
, ERRLOG_CMD_STOP
); /* copy the command */
108 *len
= ERRLOG_CMD_STOP_SIZE
; /* buffer length */
109 *chan
= CHAN_ERRLOG
; /* and channel */
110 card
->err_log_state
= ERRLOG_STATE_OFF
; /* new state is off */
111 return (1); /* tell that data should be send */
112 } /* error log start and able to send */
113 /* now handle network interface packets */
114 if ((hynet_enable
& (1 << card
->myid
)) &&
115 (skb
= hysdn_tx_netget(card
)) != NULL
)
117 if (skb
->len
<= maxlen
) {
118 memcpy(buf
, skb
->data
, skb
->len
); /* copy the packet to the buffer */
120 *chan
= CHAN_NDIS_DATA
;
121 card
->net_tx_busy
= 1; /* we are busy sending network data */
122 return (1); /* go and send the data */
124 hysdn_tx_netack(card
); /* aknowledge packet -> throw away */
125 } /* send a network packet if available */
126 #ifdef CONFIG_HYSDN_CAPI
127 if( ((hycapi_enable
& (1 << card
->myid
))) &&
128 ((skb
= hycapi_tx_capiget(card
)) != NULL
) )
130 if (skb
->len
<= maxlen
) {
131 memcpy(buf
, skb
->data
, skb
->len
);
134 hycapi_tx_capiack(card
);
135 return (1); /* go and send the data */
138 #endif /* CONFIG_HYSDN_CAPI */
139 return (0); /* nothing to send */
140 } /* hysdn_sched_tx */
143 /*****************************************************************************/
144 /* send one config line to the card and return 0 if successful, otherwise a */
145 /* negative error code. */
146 /* The function works with timeouts perhaps not giving the greatest speed */
147 /* sending the line, but this should be meaningless beacuse only some lines */
148 /* are to be sent and this happens very seldom. */
149 /*****************************************************************************/
151 hysdn_tx_cfgline(hysdn_card
*card
, unsigned char *line
, unsigned short chan
)
153 int cnt
= 50; /* timeout intervalls */
156 if (card
->debug_flags
& LOG_SCHED_ASYN
)
157 hysdn_addlog(card
, "async tx-cfg chan=%d len=%d", chan
, strlen(line
) + 1);
161 while (card
->async_busy
) {
164 if (card
->debug_flags
& LOG_SCHED_ASYN
)
165 hysdn_addlog(card
, "async tx-cfg delayed");
167 msleep_interruptible(20); /* Timeout 20ms */
169 restore_flags(flags
);
170 return (-ERR_ASYNC_TIME
); /* timed out */
173 } /* wait for buffer to become free */
175 strcpy(card
->async_data
, line
);
176 card
->async_len
= strlen(line
) + 1;
177 card
->async_channel
= chan
;
178 card
->async_busy
= 1; /* request transfer */
180 /* now queue the task */
181 schedule_work(&card
->irq_queue
);
184 if (card
->debug_flags
& LOG_SCHED_ASYN
)
185 hysdn_addlog(card
, "async tx-cfg data queued");
187 cnt
++; /* short delay */
190 while (card
->async_busy
) {
193 if (card
->debug_flags
& LOG_SCHED_ASYN
)
194 hysdn_addlog(card
, "async tx-cfg waiting for tx-ready");
196 msleep_interruptible(20); /* Timeout 20ms */
198 restore_flags(flags
);
199 return (-ERR_ASYNC_TIME
); /* timed out */
202 } /* wait for buffer to become free again */
204 restore_flags(flags
);
206 if (card
->debug_flags
& LOG_SCHED_ASYN
)
207 hysdn_addlog(card
, "async tx-cfg data send");
209 return (0); /* line send correctly */
210 } /* hysdn_tx_cfgline */