atmdev.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* atmdev.h - ATM device driver declarations and various related items */
  2. #ifndef LINUX_ATMDEV_H
  3. #define LINUX_ATMDEV_H
  4. #include <linux/wait.h> /* wait_queue_head_t */
  5. #include <linux/time.h> /* struct timeval */
  6. #include <linux/net.h>
  7. #include <linux/bug.h>
  8. #include <linux/skbuff.h> /* struct sk_buff */
  9. #include <linux/uio.h>
  10. #include <net/sock.h>
  11. #include <linux/atomic.h>
  12. #include <uapi/linux/atmdev.h>
  13. #ifdef CONFIG_PROC_FS
  14. #include <linux/proc_fs.h>
  15. extern struct proc_dir_entry *atm_proc_root;
  16. #endif
  17. #ifdef CONFIG_COMPAT
  18. #include <linux/compat.h>
  19. struct compat_atm_iobuf {
  20. int length;
  21. compat_uptr_t buffer;
  22. };
  23. #endif
  24. struct k_atm_aal_stats {
  25. #define __HANDLE_ITEM(i) atomic_t i
  26. __AAL_STAT_ITEMS
  27. #undef __HANDLE_ITEM
  28. };
  29. struct k_atm_dev_stats {
  30. struct k_atm_aal_stats aal0;
  31. struct k_atm_aal_stats aal34;
  32. struct k_atm_aal_stats aal5;
  33. };
  34. struct device;
  35. enum {
  36. ATM_VF_ADDR, /* Address is in use. Set by anybody, cleared
  37. by device driver. */
  38. ATM_VF_READY, /* VC is ready to transfer data. Set by device
  39. driver, cleared by anybody. */
  40. ATM_VF_PARTIAL, /* resources are bound to PVC (partial PVC
  41. setup), controlled by socket layer */
  42. ATM_VF_REGIS, /* registered with demon, controlled by SVC
  43. socket layer */
  44. ATM_VF_BOUND, /* local SAP is set, controlled by SVC socket
  45. layer */
  46. ATM_VF_RELEASED, /* demon has indicated/requested release,
  47. controlled by SVC socket layer */
  48. ATM_VF_HASQOS, /* QOS parameters have been set */
  49. ATM_VF_LISTEN, /* socket is used for listening */
  50. ATM_VF_META, /* SVC socket isn't used for normal data
  51. traffic and doesn't depend on signaling
  52. to be available */
  53. ATM_VF_SESSION, /* VCC is p2mp session control descriptor */
  54. ATM_VF_HASSAP, /* SAP has been set */
  55. ATM_VF_CLOSE, /* asynchronous close - treat like VF_RELEASED*/
  56. ATM_VF_WAITING, /* waiting for reply from sigd */
  57. ATM_VF_IS_CLIP, /* in use by CLIP protocol */
  58. };
  59. #define ATM_VF2VS(flags) \
  60. (test_bit(ATM_VF_READY,&(flags)) ? ATM_VS_CONNECTED : \
  61. test_bit(ATM_VF_RELEASED,&(flags)) ? ATM_VS_CLOSING : \
  62. test_bit(ATM_VF_LISTEN,&(flags)) ? ATM_VS_LISTEN : \
  63. test_bit(ATM_VF_REGIS,&(flags)) ? ATM_VS_INUSE : \
  64. test_bit(ATM_VF_BOUND,&(flags)) ? ATM_VS_BOUND : ATM_VS_IDLE)
  65. enum {
  66. ATM_DF_REMOVED, /* device was removed from atm_devs list */
  67. };
  68. #define ATM_PHY_SIG_LOST 0 /* no carrier/light */
  69. #define ATM_PHY_SIG_UNKNOWN 1 /* carrier/light status is unknown */
  70. #define ATM_PHY_SIG_FOUND 2 /* carrier/light okay */
  71. #define ATM_ATMOPT_CLP 1 /* set CLP bit */
  72. struct atm_vcc {
  73. /* struct sock has to be the first member of atm_vcc */
  74. struct sock sk;
  75. unsigned long flags; /* VCC flags (ATM_VF_*) */
  76. short vpi; /* VPI and VCI (types must be equal */
  77. /* with sockaddr) */
  78. int vci;
  79. unsigned long aal_options; /* AAL layer options */
  80. unsigned long atm_options; /* ATM layer options */
  81. struct atm_dev *dev; /* device back pointer */
  82. struct atm_qos qos; /* QOS */
  83. struct atm_sap sap; /* SAP */
  84. void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
  85. void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
  86. int (*push_oam)(struct atm_vcc *vcc,void *cell);
  87. int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
  88. void *dev_data; /* per-device data */
  89. void *proto_data; /* per-protocol data */
  90. struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
  91. /* SVC part --- may move later ------------------------------------- */
  92. short itf; /* interface number */
  93. struct sockaddr_atmsvc local;
  94. struct sockaddr_atmsvc remote;
  95. /* Multipoint part ------------------------------------------------- */
  96. struct atm_vcc *session; /* session VCC descriptor */
  97. /* Other stuff ----------------------------------------------------- */
  98. void *user_back; /* user backlink - not touched by */
  99. /* native ATM stack. Currently used */
  100. /* by CLIP and sch_atm. */
  101. };
  102. static inline struct atm_vcc *atm_sk(struct sock *sk)
  103. {
  104. return (struct atm_vcc *)sk;
  105. }
  106. static inline struct atm_vcc *ATM_SD(struct socket *sock)
  107. {
  108. return atm_sk(sock->sk);
  109. }
  110. static inline struct sock *sk_atm(struct atm_vcc *vcc)
  111. {
  112. return (struct sock *)vcc;
  113. }
  114. struct atm_dev_addr {
  115. struct sockaddr_atmsvc addr; /* ATM address */
  116. struct list_head entry; /* next address */
  117. };
  118. enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
  119. struct atm_dev {
  120. const struct atmdev_ops *ops; /* device operations; NULL if unused */
  121. const struct atmphy_ops *phy; /* PHY operations, may be undefined */
  122. /* (NULL) */
  123. const char *type; /* device type name */
  124. int number; /* device index */
  125. void *dev_data; /* per-device data */
  126. void *phy_data; /* private PHY date */
  127. unsigned long flags; /* device flags (ATM_DF_*) */
  128. struct list_head local; /* local ATM addresses */
  129. struct list_head lecs; /* LECS ATM addresses learned via ILMI */
  130. unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
  131. struct atm_cirange ci_range; /* VPI/VCI range */
  132. struct k_atm_dev_stats stats; /* statistics */
  133. char signal; /* signal status (ATM_PHY_SIG_*) */
  134. int link_rate; /* link rate (default: OC3) */
  135. atomic_t refcnt; /* reference count */
  136. spinlock_t lock; /* protect internal members */
  137. #ifdef CONFIG_PROC_FS
  138. struct proc_dir_entry *proc_entry; /* proc entry */
  139. char *proc_name; /* proc entry name */
  140. #endif
  141. struct device class_dev; /* sysfs device */
  142. struct list_head dev_list; /* linkage */
  143. };
  144. /* OF: send_Oam Flags */
  145. #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
  146. #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
  147. /*
  148. * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
  149. */
  150. struct atmdev_ops { /* only send is required */
  151. void (*dev_close)(struct atm_dev *dev);
  152. int (*open)(struct atm_vcc *vcc);
  153. void (*close)(struct atm_vcc *vcc);
  154. int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
  155. #ifdef CONFIG_COMPAT
  156. int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
  157. void __user *arg);
  158. #endif
  159. int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
  160. void __user *optval,int optlen);
  161. int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
  162. void __user *optval,unsigned int optlen);
  163. int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
  164. int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
  165. void (*phy_put)(struct atm_dev *dev,unsigned char value,
  166. unsigned long addr);
  167. unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
  168. int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
  169. int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
  170. struct module *owner;
  171. };
  172. struct atmphy_ops {
  173. int (*start)(struct atm_dev *dev);
  174. int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
  175. void (*interrupt)(struct atm_dev *dev);
  176. int (*stop)(struct atm_dev *dev);
  177. };
  178. struct atm_skb_data {
  179. struct atm_vcc *vcc; /* ATM VCC */
  180. unsigned long atm_options; /* ATM layer options */
  181. };
  182. #define VCC_HTABLE_SIZE 32
  183. extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
  184. extern rwlock_t vcc_sklist_lock;
  185. #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
  186. struct atm_dev *atm_dev_register(const char *type, struct device *parent,
  187. const struct atmdev_ops *ops,
  188. int number, /* -1 == pick first available */
  189. unsigned long *flags);
  190. struct atm_dev *atm_dev_lookup(int number);
  191. void atm_dev_deregister(struct atm_dev *dev);
  192. /* atm_dev_signal_change
  193. *
  194. * Propagate lower layer signal change in atm_dev->signal to netdevice.
  195. * The event will be sent via a notifier call chain.
  196. */
  197. void atm_dev_signal_change(struct atm_dev *dev, char signal);
  198. void vcc_insert_socket(struct sock *sk);
  199. void atm_dev_release_vccs(struct atm_dev *dev);
  200. static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
  201. {
  202. atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
  203. }
  204. static inline void atm_return(struct atm_vcc *vcc,int truesize)
  205. {
  206. atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
  207. }
  208. static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
  209. {
  210. return (size + atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) <
  211. sk_atm(vcc)->sk_sndbuf;
  212. }
  213. static inline void atm_dev_hold(struct atm_dev *dev)
  214. {
  215. atomic_inc(&dev->refcnt);
  216. }
  217. static inline void atm_dev_put(struct atm_dev *dev)
  218. {
  219. if (atomic_dec_and_test(&dev->refcnt)) {
  220. BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
  221. if (dev->ops->dev_close)
  222. dev->ops->dev_close(dev);
  223. put_device(&dev->class_dev);
  224. }
  225. }
  226. int atm_charge(struct atm_vcc *vcc,int truesize);
  227. struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
  228. gfp_t gfp_flags);
  229. int atm_pcr_goal(const struct atm_trafprm *tp);
  230. void vcc_release_async(struct atm_vcc *vcc, int reply);
  231. struct atm_ioctl {
  232. struct module *owner;
  233. /* A module reference is kept if appropriate over this call.
  234. * Return -ENOIOCTLCMD if you don't handle it. */
  235. int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
  236. struct list_head list;
  237. };
  238. /**
  239. * register_atm_ioctl - register handler for ioctl operations
  240. *
  241. * Special (non-device) handlers of ioctl's should
  242. * register here. If you're a normal device, you should
  243. * set .ioctl in your atmdev_ops instead.
  244. */
  245. void register_atm_ioctl(struct atm_ioctl *);
  246. /**
  247. * deregister_atm_ioctl - remove the ioctl handler
  248. */
  249. void deregister_atm_ioctl(struct atm_ioctl *);
  250. /* register_atmdevice_notifier - register atm_dev notify events
  251. *
  252. * Clients like br2684 will register notify events
  253. * Currently we notify of signal found/lost
  254. */
  255. int register_atmdevice_notifier(struct notifier_block *nb);
  256. void unregister_atmdevice_notifier(struct notifier_block *nb);
  257. #endif