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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* atmdev.h - ATM device driver declarations and various related items */
  2.  
  3. /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
  4.  
  5. #ifndef LINUX_ATMDEV_H
  6. #define LINUX_ATMDEV_H
  7. #include <linux/config.h>
  8. #include <linux/atmapi.h>
  9. #include <linux/atm.h>
  10. #include <linux/atmioc.h>
  11. #define ESI_LEN 6
  12. #define ATM_OC3_PCR (155520000/270*260/8/53)
  13. /* OC3 link rate:  155520000 bps
  14.    SONET overhead: /270*260 (9 section, 1 path)
  15.    bits per cell:  /8/53
  16.    max cell rate:  353207.547 cells/sec */
  17. #define ATM_25_PCR ((25600000/8-8000)/54)
  18. /* 25 Mbps ATM cell rate (59111) */
  19. #define ATM_OC12_PCR (622080000/1080*1040/8/53)
  20. /* OC12 link rate: 622080000 bps
  21.    SONET overhead: /1080*1040
  22.    bits per cell:  /8/53
  23.    max cell rate:  1412830.188 cells/sec */
  24. #define ATM_DS3_PCR (8000*12)
  25. /* DS3: 12 cells in a 125 usec time slot */
  26. #define ATM_PDU_OVHD 0 /* number of bytes to charge against buffer
  27.    quota per PDU */
  28. #define ATM_SD(s) ((s)->sk->protinfo.af_atm)
  29. #define __AAL_STAT_ITEMS 
  30.     __HANDLE_ITEM(tx); /* TX okay */ 
  31.     __HANDLE_ITEM(tx_err); /* TX errors */ 
  32.     __HANDLE_ITEM(rx); /* RX okay */ 
  33.     __HANDLE_ITEM(rx_err); /* RX errors */ 
  34.     __HANDLE_ITEM(rx_drop); /* RX out of memory */
  35. struct atm_aal_stats {
  36. #define __HANDLE_ITEM(i) int i
  37. __AAL_STAT_ITEMS
  38. #undef __HANDLE_ITEM
  39. };
  40. struct atm_dev_stats {
  41. struct atm_aal_stats aal0;
  42. struct atm_aal_stats aal34;
  43. struct atm_aal_stats aal5;
  44. } __ATM_API_ALIGN;
  45. #define ATM_GETLINKRATE _IOW('a',ATMIOC_ITF+1,struct atmif_sioc)
  46. /* get link rate */
  47. #define ATM_GETNAMES _IOW('a',ATMIOC_ITF+3,struct atm_iobuf)
  48. /* get interface names (numbers) */
  49. #define ATM_GETTYPE _IOW('a',ATMIOC_ITF+4,struct atmif_sioc)
  50. /* get interface type name */
  51. #define ATM_GETESI _IOW('a',ATMIOC_ITF+5,struct atmif_sioc)
  52. /* get interface ESI */
  53. #define ATM_GETADDR _IOW('a',ATMIOC_ITF+6,struct atmif_sioc)
  54. /* get itf's local ATM addr. list */
  55. #define ATM_RSTADDR _IOW('a',ATMIOC_ITF+7,struct atmif_sioc)
  56. /* reset itf's ATM address list */
  57. #define ATM_ADDADDR _IOW('a',ATMIOC_ITF+8,struct atmif_sioc)
  58. /* add a local ATM address */
  59. #define ATM_DELADDR _IOW('a',ATMIOC_ITF+9,struct atmif_sioc)
  60. /* remove a local ATM address */
  61. #define ATM_GETCIRANGE _IOW('a',ATMIOC_ITF+10,struct atmif_sioc)
  62. /* get connection identifier range */
  63. #define ATM_SETCIRANGE _IOW('a',ATMIOC_ITF+11,struct atmif_sioc)
  64. /* set connection identifier range */
  65. #define ATM_SETESI _IOW('a',ATMIOC_ITF+12,struct atmif_sioc)
  66. /* set interface ESI */
  67. #define ATM_SETESIF _IOW('a',ATMIOC_ITF+13,struct atmif_sioc)
  68. /* force interface ESI */
  69. #define ATM_GETSTAT _IOW('a',ATMIOC_SARCOM+0,struct atmif_sioc)
  70. /* get AAL layer statistics */
  71. #define ATM_GETSTATZ _IOW('a',ATMIOC_SARCOM+1,struct atmif_sioc)
  72. /* get AAL layer statistics and zero */
  73. #define ATM_GETLOOP _IOW('a',ATMIOC_SARCOM+2,struct atmif_sioc)
  74. /* get loopback mode */
  75. #define ATM_SETLOOP _IOW('a',ATMIOC_SARCOM+3,struct atmif_sioc)
  76. /* set loopback mode */
  77. #define ATM_QUERYLOOP _IOW('a',ATMIOC_SARCOM+4,struct atmif_sioc)
  78. /* query supported loopback modes */
  79. #define ATM_SETSC _IOW('a',ATMIOC_SPECIAL+1,int)
  80. /* enable or disable single-copy */
  81. #define ATM_SETBACKEND _IOW('a',ATMIOC_SPECIAL+2,atm_backend_t)
  82. /* set backend handler */
  83. #define ATM_NEWBACKENDIF _IOW('a',ATMIOC_SPECIAL+3,atm_backend_t)
  84. /* use backend to make new if */
  85. /*
  86.  * These are backend handkers that can be set via the ATM_SETBACKEND call
  87.  * above.  In the future we may support dynamic loading of these - for now,
  88.  * they're just being used to share the ATMIOC_BACKEND ioctls
  89.  */
  90. #define ATM_BACKEND_RAW 0
  91. #define ATM_BACKEND_PPP 1 /* PPPoATM - RFC2364 */
  92. #define ATM_BACKEND_BR2684 2 /* Bridged RFC1483/2684 */
  93. /* for ATM_GETTYPE */
  94. #define ATM_ITFTYP_LEN 8 /* maximum length of interface type name */
  95. /*
  96.  * Loopback modes for ATM_{PHY,SAR}_{GET,SET}LOOP
  97.  */
  98. /* Point of loopback CPU-->SAR-->PHY-->line--> ... */
  99. #define __ATM_LM_NONE 0 /* no loop back     ^     ^     ^      ^      */
  100. #define __ATM_LM_AAL 1 /* loop back PDUs --'     |     |      |      */
  101. #define __ATM_LM_ATM 2 /* loop back ATM cells ---'     |      |      */
  102. /* RESERVED 4 loop back on PHY side  ---'       */
  103. #define __ATM_LM_PHY 8 /* loop back bits (digital) ----'      |      */
  104. #define __ATM_LM_ANALOG 16 /* loop back the analog signal --------'      */
  105. /* Direction of loopback */
  106. #define __ATM_LM_MKLOC(n) ((n))     /* Local (i.e. loop TX to RX) */
  107. #define __ATM_LM_MKRMT(n) ((n) << 8)  /* Remote (i.e. loop RX to TX) */
  108. #define __ATM_LM_XTLOC(n) ((n) & 0xff)
  109. #define __ATM_LM_XTRMT(n) (((n) >> 8) & 0xff)
  110. #define ATM_LM_NONE 0 /* no loopback */
  111. #define ATM_LM_LOC_AAL __ATM_LM_MKLOC(__ATM_LM_AAL)
  112. #define ATM_LM_LOC_ATM __ATM_LM_MKLOC(__ATM_LM_ATM)
  113. #define ATM_LM_LOC_PHY __ATM_LM_MKLOC(__ATM_LM_PHY)
  114. #define ATM_LM_LOC_ANALOG __ATM_LM_MKLOC(__ATM_LM_ANALOG)
  115. #define ATM_LM_RMT_AAL __ATM_LM_MKRMT(__ATM_LM_AAL)
  116. #define ATM_LM_RMT_ATM __ATM_LM_MKRMT(__ATM_LM_ATM)
  117. #define ATM_LM_RMT_PHY __ATM_LM_MKRMT(__ATM_LM_PHY)
  118. #define ATM_LM_RMT_ANALOG __ATM_LM_MKRMT(__ATM_LM_ANALOG)
  119. /*
  120.  * Note: ATM_LM_LOC_* and ATM_LM_RMT_* can be combined, provided that
  121.  * __ATM_LM_XTLOC(x) <= __ATM_LM_XTRMT(x)
  122.  */
  123. struct atm_iobuf {
  124. int length;
  125. void *buffer;
  126. };
  127. /* for ATM_GETCIRANGE / ATM_SETCIRANGE */
  128. #define ATM_CI_MAX      -1              /* use maximum range of VPI/VCI */
  129.  
  130. struct atm_cirange {
  131. char vpi_bits; /* 1..8, ATM_CI_MAX (-1) for maximum */
  132. char vci_bits; /* 1..16, ATM_CI_MAX (-1) for maximum */
  133. };
  134. /* for ATM_SETSC; actually taken from the ATM_VF number space */
  135. #define ATM_SC_RX 1024 /* enable RX single-copy */
  136. #define ATM_SC_TX 2048 /* enable TX single-copy */
  137. #define ATM_BACKLOG_DEFAULT 32 /* if we get more, we're likely to time out
  138.   anyway */
  139. /* MF: change_qos (Modify) flags */
  140. #define ATM_MF_IMMED  1 /* Block until change is effective */
  141. #define ATM_MF_INC_RSV  2 /* Change reservation on increase */
  142. #define ATM_MF_INC_SHP  4 /* Change shaping on increase */
  143. #define ATM_MF_DEC_RSV  8 /* Change reservation on decrease */
  144. #define ATM_MF_DEC_SHP 16 /* Change shaping on decrease */
  145. #define ATM_MF_BWD 32 /* Set the backward direction parameters */
  146. #define ATM_MF_SET (ATM_MF_INC_RSV | ATM_MF_INC_SHP | ATM_MF_DEC_RSV | 
  147.   ATM_MF_DEC_SHP | ATM_MF_BWD)
  148. /*
  149.  * ATM_VS_* are used to express VC state in a human-friendly way.
  150.  */
  151. #define ATM_VS_IDLE 0 /* VC is not used */
  152. #define ATM_VS_CONNECTED 1 /* VC is connected */
  153. #define ATM_VS_CLOSING 2 /* VC is closing */
  154. #define ATM_VS_LISTEN 3 /* VC is listening for incoming setups */
  155. #define ATM_VS_INUSE 4 /* VC is in use (registered with atmsigd) */
  156. #define ATM_VS_BOUND 5 /* VC is bound */
  157. #define ATM_VS2TXT_MAP 
  158.     "IDLE", "CONNECTED", "CLOSING", "LISTEN", "INUSE", "BOUND"
  159. #define ATM_VF2TXT_MAP 
  160.     "ADDR", "READY", "PARTIAL", "REGIS", 
  161.     "RELEASED", "HASQOS", "LISTEN", "META", 
  162.     "256", "512", "1024", "2048", 
  163.     "SESSION", "HASSAP", "BOUND", "CLOSE"
  164. #ifndef __KERNEL__
  165. #undef __AAL_STAT_ITEMS
  166. #else
  167. #include <linux/sched.h> /* wait_queue_head_t */
  168. #include <linux/time.h> /* struct timeval */
  169. #include <linux/net.h>
  170. #include <linux/skbuff.h> /* struct sk_buff */
  171. #include <linux/uio.h>
  172. #include <net/sock.h>
  173. #include <asm/atomic.h>
  174. #ifdef CONFIG_PROC_FS
  175. #include <linux/proc_fs.h>
  176. #endif
  177. struct k_atm_aal_stats {
  178. #define __HANDLE_ITEM(i) atomic_t i
  179. __AAL_STAT_ITEMS
  180. #undef __HANDLE_ITEM
  181. };
  182. struct k_atm_dev_stats {
  183. struct k_atm_aal_stats aal0;
  184. struct k_atm_aal_stats aal34;
  185. struct k_atm_aal_stats aal5;
  186. };
  187. enum {
  188. ATM_VF_ADDR, /* Address is in use. Set by anybody, cleared
  189.    by device driver. */
  190. ATM_VF_READY, /* VC is ready to transfer data. Set by device
  191.    driver, cleared by anybody. */
  192. ATM_VF_PARTIAL, /* resources are bound to PVC (partial PVC
  193.    setup), controlled by socket layer */
  194. ATM_VF_REGIS, /* registered with demon, controlled by SVC
  195.    socket layer */
  196. ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
  197.    layer */
  198. ATM_VF_RELEASED, /* demon has indicated/requested release,
  199.    controlled by SVC socket layer */
  200. ATM_VF_HASQOS, /* QOS parameters have been set */
  201. ATM_VF_LISTEN, /* socket is used for listening */
  202. ATM_VF_META, /* SVC socket isn't used for normal data
  203.    traffic and doesn't depend on signaling
  204.    to be available */
  205. ATM_VF_SESSION, /* VCC is p2mp session control descriptor */
  206. ATM_VF_HASSAP, /* SAP has been set */
  207. ATM_VF_CLOSE, /* asynchronous close - treat like VF_RELEASED*/
  208. };
  209. #define ATM_VF2VS(flags) 
  210.     (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : 
  211.      test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : 
  212.      test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : 
  213.      test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : 
  214.      test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
  215. enum {
  216. ATM_DF_CLOSE, /* close device when last VCC is closed */
  217. };
  218. #define ATM_PHY_SIG_LOST    0 /* no carrier/light */
  219. #define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
  220. #define ATM_PHY_SIG_FOUND   2 /* carrier/light okay */
  221. #define ATM_ATMOPT_CLP 1 /* set CLP bit */
  222. typedef struct { unsigned long bits; } atm_vcc_flags_t;
  223. struct atm_vcc {
  224. atm_vcc_flags_t flags; /* VCC flags (ATM_VF_*) */
  225. unsigned char family; /* address family; 0 if unused */
  226. short vpi; /* VPI and VCI (types must be equal */
  227. /* with sockaddr) */
  228. int  vci;
  229. unsigned long aal_options; /* AAL layer options */
  230. unsigned long atm_options; /* ATM layer options */
  231. struct atm_dev *dev; /* device back pointer */
  232. struct atm_qos qos; /* QOS */
  233. struct atm_sap sap; /* SAP */
  234. atomic_t tx_inuse,rx_inuse; /* buffer space in use */
  235. void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
  236. void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
  237. struct sk_buff *(*alloc_tx)(struct atm_vcc *vcc,unsigned int size);
  238. /* TX allocation routine - can be */
  239. /* modified by protocol or by driver.*/
  240. /* NOTE: this interface will change */
  241. int (*push_oam)(struct atm_vcc *vcc,void *cell);
  242. int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
  243. void *dev_data; /* per-device data */
  244. void *proto_data; /* per-protocol data */
  245. struct timeval timestamp; /* AAL timestamps */
  246. struct sk_buff_head recvq; /* receive queue */
  247. struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
  248. wait_queue_head_t sleep; /* if socket is busy */
  249. struct sock *sk; /* socket backpointer */
  250. struct atm_vcc *prev,*next;
  251. /* SVC part --- may move later ------------------------------------- */
  252. short itf; /* interface number */
  253. struct sockaddr_atmsvc local;
  254. struct sockaddr_atmsvc remote;
  255. void (*callback)(struct atm_vcc *vcc);
  256. struct sk_buff_head listenq;
  257. int backlog_quota; /* number of connection requests we */
  258. /* can still accept */
  259. int reply; /* also used by ATMTCP */
  260. /* Multipoint part ------------------------------------------------- */
  261. struct atm_vcc *session; /* session VCC descriptor */
  262. /* Other stuff ----------------------------------------------------- */
  263. void *user_back; /* user backlink - not touched by */
  264. /* native ATM stack. Currently used */
  265. /* by CLIP and sch_atm. */
  266. };
  267. struct atm_dev_addr {
  268. struct sockaddr_atmsvc addr; /* ATM address */
  269. struct atm_dev_addr *next; /* next address */
  270. };
  271. typedef struct { unsigned int bits; } atm_dev_flags_t;
  272. struct atm_dev {
  273. const struct atmdev_ops *ops; /* device operations; NULL if unused */
  274. const struct atmphy_ops *phy; /* PHY operations, may be undefined */
  275. /* (NULL) */
  276. const char *type; /* device type name */
  277. int number; /* device index */
  278. struct atm_vcc *vccs; /* VCC table (or NULL) */
  279. struct atm_vcc *last; /* last VCC (or undefined) */
  280. void *dev_data; /* per-device data */
  281. void *phy_data; /* private PHY date */
  282. atm_dev_flags_t flags; /* device flags (ATM_DF_*) */
  283. struct atm_dev_addr *local; /* local ATM addresses */
  284. unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
  285. struct atm_cirange ci_range; /* VPI/VCI range */
  286. struct k_atm_dev_stats stats; /* statistics */
  287. char signal; /* signal status (ATM_PHY_SIG_*) */
  288. int link_rate; /* link rate (default: OC3) */
  289. #ifdef CONFIG_PROC_FS
  290. struct proc_dir_entry *proc_entry; /* proc entry */
  291. char *proc_name; /* proc entry name */
  292. #endif
  293. struct atm_dev *prev,*next; /* linkage */
  294. };
  295. /*
  296.  * ioctl, getsockopt, setsockopt, and sg_send are optional and can be set to
  297.  * NULL. */
  298. /* OF: send_Oam Flags */
  299. #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
  300. #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
  301. struct atmdev_ops { /* only send is required */
  302. void (*dev_close)(struct atm_dev *dev);
  303. int (*open)(struct atm_vcc *vcc,short vpi,int vci);
  304. void (*close)(struct atm_vcc *vcc);
  305. int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
  306. int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
  307.     void *optval,int optlen);
  308. int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
  309.     void *optval,int optlen);
  310. int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
  311. int (*sg_send)(struct atm_vcc *vcc,unsigned long start,
  312.     unsigned long size);
  313. #if 0 /* keep the current hack for now */
  314. int (*send_iovec)(struct atm_vcc *vcc,struct iovec *iov,int size,
  315.     void (*discard)(struct atm_vcc *vcc,void *user),void *user);
  316. #endif
  317. int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
  318. void (*phy_put)(struct atm_dev *dev,unsigned char value,
  319.     unsigned long addr);
  320. unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
  321. void (*feedback)(struct atm_vcc *vcc,struct sk_buff *skb,
  322.     unsigned long start,unsigned long dest,int len);
  323. int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
  324. void (*free_rx_skb)(struct atm_vcc *vcc, struct sk_buff *skb);
  325. /* @@@ temporary hack */
  326. int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
  327. struct module *owner;
  328. };
  329. struct atmphy_ops {
  330. int (*start)(struct atm_dev *dev);
  331. int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void *arg);
  332. void (*interrupt)(struct atm_dev *dev);
  333. int (*stop)(struct atm_dev *dev);
  334. };
  335. struct atm_skb_data {
  336. struct atm_vcc *vcc; /* ATM VCC */
  337. int iovcnt; /* 0 for "normal" operation */
  338. unsigned long atm_options; /* ATM layer options */
  339. };
  340. #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
  341. struct atm_dev *atm_dev_register(const char *type,const struct atmdev_ops *ops,
  342.     int number,atm_dev_flags_t *flags); /* number == -1: pick first available */
  343. struct atm_dev *atm_find_dev(int number);
  344. void atm_dev_deregister(struct atm_dev *dev);
  345. void shutdown_atm_dev(struct atm_dev *dev);
  346. void bind_vcc(struct atm_vcc *vcc,struct atm_dev *dev);
  347. /*
  348.  * This is approximately the algorithm used by alloc_skb.
  349.  *
  350.  */
  351. static __inline__ int atm_guess_pdu2truesize(int pdu_size)
  352. {
  353. return ((pdu_size+15) & ~15) + sizeof(struct sk_buff);
  354. }
  355. static __inline__ void atm_force_charge(struct atm_vcc *vcc,int truesize)
  356. {
  357. atomic_add(truesize+ATM_PDU_OVHD,&vcc->rx_inuse);
  358. }
  359. static __inline__ void atm_return(struct atm_vcc *vcc,int truesize)
  360. {
  361. atomic_sub(truesize+ATM_PDU_OVHD,&vcc->rx_inuse);
  362. }
  363. static __inline__ int atm_may_send(struct atm_vcc *vcc,unsigned int size)
  364. {
  365. return size+atomic_read(&vcc->tx_inuse)+ATM_PDU_OVHD < vcc->sk->sndbuf;
  366. }
  367. int atm_charge(struct atm_vcc *vcc,int truesize);
  368. struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
  369.     int gfp_flags);
  370. int atm_find_ci(struct atm_vcc *vcc,short *vpi,int *vci);
  371. int atm_pcr_goal(struct atm_trafprm *tp);
  372. void atm_async_release_vcc(struct atm_vcc *vcc,int reply);
  373. #endif /* __KERNEL__ */
  374. #endif