hysdn_sched.c 7.1 KB

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