layer2.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * PCBIT-D low-layer interface definitions
  3.  *
  4.  * Copyright (C) 1996 Universidade de Lisboa
  5.  * 
  6.  * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
  7.  *
  8.  * This software may be used and distributed according to the terms of 
  9.  * the GNU General Public License, incorporated herein by reference.
  10.  */
  11. /*
  12.  * 19991203 - Fernando Carvalho - takion@superbofh.org
  13.  * Hacked to compile with egcs and run with current version of isdn modules
  14. */
  15. #ifndef LAYER2_H
  16. #define LAYER2_H
  17. #include <asm/byteorder.h>
  18. #define BANK1 0x0000U /* PC -> Board */
  19. #define BANK2 0x01ffU /* Board -> PC */
  20. #define BANK3 0x03feU /* Att Board */
  21. #define BANK4 0x03ffU /* Att PC */
  22. #define BANKLEN 0x01FFU
  23. #define LOAD_ZONE_START 0x03f8U
  24. #define LOAD_ZONE_END   0x03fdU
  25. #define LOAD_RETRY      18000000
  26. /* TAM - XX - C - S  - NUM */
  27. #define PREHDR_LEN 8
  28. /* TT  - M  - I - TH - TD  */      
  29. #define FRAME_HDR_LEN  8   
  30. #define MSG_CONN_REQ 0x08000100
  31. #define MSG_CONN_CONF 0x00000101
  32. #define MSG_CONN_IND 0x00000102
  33. #define MSG_CONN_RESP 0x08000103
  34. #define MSG_CONN_ACTV_REQ 0x08000300
  35. #define MSG_CONN_ACTV_CONF 0x00000301
  36. #define MSG_CONN_ACTV_IND 0x00000302
  37. #define MSG_CONN_ACTV_RESP 0x08000303
  38. #define MSG_DISC_REQ 0x08000400
  39. #define MSG_DISC_CONF 0x00000401
  40. #define MSG_DISC_IND 0x00000402
  41. #define MSG_DISC_RESP 0x08000403
  42. #define MSG_TDATA_REQ 0x0908E200
  43. #define MSG_TDATA_CONF 0x0000E201
  44. #define MSG_TDATA_IND 0x0000E202
  45. #define MSG_TDATA_RESP 0x0908E203
  46. #define MSG_SELP_REQ 0x09004000
  47. #define MSG_SELP_CONF 0x00004001
  48. #define MSG_ACT_TRANSP_REQ      0x0908E000
  49. #define MSG_ACT_TRANSP_CONF     0x0000E001
  50. #define MSG_STPROT_REQ 0x09004100
  51. #define MSG_STPROT_CONF 0x00004101
  52. #define MSG_PING188_REQ 0x09030500
  53. #define MSG_PING188_CONF        0x000005bc
  54. #define MSG_WATCH188         0x09030400
  55. #define MSG_API_ON              0x08020102
  56. #define MSG_POOL_PCBIT          0x08020400
  57. #define MSG_POOL_PCBIT_CONF     0x00000401
  58. #define MSG_INFO_IND            0x00002602
  59. #define MSG_INFO_RESP           0x08002603
  60. #define MSG_DEBUG_188           0x0000ff00
  61. /*
  62.    
  63.    long  4 3 2 1
  64.    Intel 1 2 3 4
  65. */
  66. #ifdef __LITTLE_ENDIAN
  67. #define SET_MSG_SCMD(msg, ch)  (msg = (msg & 0xffffff00) | (((ch) & 0xff)))
  68. #define SET_MSG_CMD(msg, ch)  (msg = (msg & 0xffff00ff) | (((ch) & 0xff) << 8))
  69. #define SET_MSG_PROC(msg, ch)  (msg = (msg & 0xff00ffff) | (((ch) & 0xff) << 16))
  70. #define SET_MSG_CPU(msg, ch)  (msg = (msg & 0x00ffffff) | (((ch) & 0xff) << 24))
  71. #define GET_MSG_SCMD(msg)  ((msg) & 0xFF)
  72. #define GET_MSG_CMD(msg)  ((msg) >> 8 & 0xFF)
  73. #define GET_MSG_PROC(msg)  ((msg) >> 16 & 0xFF)
  74. #define GET_MSG_CPU(msg)  ((msg) >> 24)
  75. #else
  76. #error "Non-Intel CPU"
  77. #endif
  78. #define MAX_QUEUED 7
  79. #define SCHED_READ    0x01
  80. #define SCHED_WRITE   0x02
  81. #define SET_RUN_TIMEOUT 2*HZ /* 2 seconds */
  82.      
  83. struct frame_buf {
  84.         ulong msg;
  85.         unsigned int refnum;
  86.         unsigned int dt_len;
  87.         unsigned int hdr_len;
  88.         struct sk_buff *skb;
  89. unsigned int copied;
  90.         struct frame_buf * next;
  91. };
  92. extern int pcbit_l2_write(struct pcbit_dev * dev, ulong msg, ushort refnum, 
  93.                           struct sk_buff *skb, unsigned short hdr_len);
  94. extern void pcbit_irq_handler(int interrupt, void *, struct pt_regs *regs);
  95. extern struct pcbit_dev * dev_pcbit[MAX_PCBIT_CARDS];
  96. #ifdef DEBUG
  97. static __inline__ void log_state(struct pcbit_dev *dev) {
  98.         printk(KERN_DEBUG "writeptr = %ldn", 
  99.        (ulong) (dev->writeptr - dev->sh_mem));
  100.         printk(KERN_DEBUG "readptr  = %ldn", 
  101.        (ulong) (dev->readptr - (dev->sh_mem + BANK2)));
  102.         printk(KERN_DEBUG "{rcv_seq=%01x, send_seq=%01x, unack_seq=%01x}n", 
  103.        dev->rcv_seq, dev->send_seq, dev->unack_seq);
  104. }
  105. #endif
  106. static __inline__ struct pcbit_dev * chan2dev(struct pcbit_chan * chan) 
  107. {
  108.         struct pcbit_dev * dev;
  109.         int i;
  110.         for (i=0; i<MAX_PCBIT_CARDS; i++)
  111.                 if ((dev=dev_pcbit[i]))
  112.                         if (dev->b1 == chan || dev->b2 == chan)
  113.                                 return dev;
  114.         return NULL;
  115. }
  116. static __inline__ struct pcbit_dev * finddev(int id)
  117. {
  118.   struct pcbit_dev * dev;
  119.   int i;
  120.   for (i=0; i<MAX_PCBIT_CARDS; i++)
  121.     if ((dev=dev_pcbit[i]))
  122.       if (dev->id == id)
  123. return dev;
  124.   return NULL;
  125. }
  126. /*
  127.  *  Support routines for reading and writing in the board
  128.  */
  129. static __inline__ void pcbit_writeb(struct pcbit_dev *dev, unsigned char dt)
  130. {
  131.   writeb(dt, dev->writeptr++);
  132.   if (dev->writeptr == dev->sh_mem + BANKLEN)
  133.     dev->writeptr = dev->sh_mem;
  134. }
  135. static __inline__ void pcbit_writew(struct pcbit_dev *dev, unsigned short dt)
  136. {
  137.   int dist;
  138.   dist = BANKLEN - (dev->writeptr - dev->sh_mem);
  139.   switch (dist) {
  140.   case 2:
  141.     writew(dt, dev->writeptr);
  142.     dev->writeptr = dev->sh_mem;
  143.     break;
  144.   case 1:
  145.     writeb((u_char) (dt & 0x00ffU), dev->writeptr);    
  146.     dev->writeptr = dev->sh_mem;
  147.     writeb((u_char) (dt >> 8), dev->writeptr++);    
  148.     break;
  149.   default:
  150.     writew(dt, dev->writeptr);
  151.     dev->writeptr += 2;
  152.     break;
  153.   };
  154. }
  155. static __inline__ void memcpy_topcbit(struct pcbit_dev * dev, u_char * data, 
  156.       int len)
  157. {
  158.   int diff;
  159.   diff = len - (BANKLEN - (dev->writeptr - dev->sh_mem) );
  160.   if (diff > 0)
  161.     {
  162.       memcpy_toio(dev->writeptr, data, len - diff);
  163.       memcpy_toio(dev->sh_mem, data + (len - diff), diff);
  164.       dev->writeptr = dev->sh_mem + diff;
  165.     }
  166.   else
  167.     {
  168.       memcpy_toio(dev->writeptr, data, len);
  169.       dev->writeptr += len;
  170.       if (diff == 0)
  171. dev->writeptr = dev->sh_mem;
  172.     }
  173. }
  174. static __inline__ unsigned char pcbit_readb(struct pcbit_dev *dev)
  175. {
  176.   unsigned char val;
  177.   val = readb(dev->readptr++);
  178.   if (dev->readptr == dev->sh_mem + BANK2 + BANKLEN)
  179.     dev->readptr = dev->sh_mem + BANK2;
  180.   return val;
  181. }
  182. static __inline__ unsigned short pcbit_readw(struct pcbit_dev *dev)
  183. {
  184.   int dist;
  185.   unsigned short val;
  186.   dist = BANKLEN - ( dev->readptr - (dev->sh_mem + BANK2 ) );
  187.   switch (dist) {
  188.   case 2:
  189.     val = readw(dev->readptr);
  190.     dev->readptr = dev->sh_mem + BANK2;
  191.     break;
  192.   case 1:
  193.     val = readb(dev->readptr);
  194.     dev->readptr = dev->sh_mem + BANK2;
  195.     val = (readb(dev->readptr++) << 8) | val;
  196.     break;
  197.   default:
  198.     val = readw(dev->readptr);
  199.     dev->readptr += 2;
  200.     break;
  201.   };
  202.   return val;
  203. }
  204. static __inline__ void memcpy_frompcbit(struct pcbit_dev * dev, u_char * data, int len)
  205. {
  206.   int diff;
  207.   diff = len - (BANKLEN - (dev->readptr - (dev->sh_mem + BANK2) ) ); 
  208.   if (diff > 0)
  209.     {
  210.       memcpy_fromio(data, dev->readptr, len - diff);
  211.       memcpy_fromio(data + (len - diff), dev->sh_mem + BANK2 , diff);
  212.       dev->readptr = dev->sh_mem + BANK2 + diff;
  213.     }
  214.   else
  215.     {
  216.       memcpy_fromio(data, dev->readptr, len);
  217.       dev->readptr += len;
  218.       if (diff == 0)
  219. dev->readptr = dev->sh_mem + BANK2;
  220.     }
  221. }
  222. #endif