atmdev.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 (*release_cb)(struct atm_vcc *vcc); /* release_sock callback */
  85. void (*push)(struct atm_vcc *vcc,struct sk_buff *skb);
  86. void (*pop)(struct atm_vcc *vcc,struct sk_buff *skb); /* optional */
  87. int (*push_oam)(struct atm_vcc *vcc,void *cell);
  88. int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
  89. void *dev_data; /* per-device data */
  90. void *proto_data; /* per-protocol data */
  91. struct k_atm_aal_stats *stats; /* pointer to AAL stats group */
  92. struct module *owner; /* owner of ->push function */
  93. /* SVC part --- may move later ------------------------------------- */
  94. short itf; /* interface number */
  95. struct sockaddr_atmsvc local;
  96. struct sockaddr_atmsvc remote;
  97. /* Multipoint part ------------------------------------------------- */
  98. struct atm_vcc *session; /* session VCC descriptor */
  99. /* Other stuff ----------------------------------------------------- */
  100. void *user_back; /* user backlink - not touched by */
  101. /* native ATM stack. Currently used */
  102. /* by CLIP and sch_atm. */
  103. };
  104. static inline struct atm_vcc *atm_sk(struct sock *sk)
  105. {
  106. return (struct atm_vcc *)sk;
  107. }
  108. static inline struct atm_vcc *ATM_SD(struct socket *sock)
  109. {
  110. return atm_sk(sock->sk);
  111. }
  112. static inline struct sock *sk_atm(struct atm_vcc *vcc)
  113. {
  114. return (struct sock *)vcc;
  115. }
  116. struct atm_dev_addr {
  117. struct sockaddr_atmsvc addr; /* ATM address */
  118. struct list_head entry; /* next address */
  119. };
  120. enum atm_addr_type_t { ATM_ADDR_LOCAL, ATM_ADDR_LECS };
  121. struct atm_dev {
  122. const struct atmdev_ops *ops; /* device operations; NULL if unused */
  123. const struct atmphy_ops *phy; /* PHY operations, may be undefined */
  124. /* (NULL) */
  125. const char *type; /* device type name */
  126. int number; /* device index */
  127. void *dev_data; /* per-device data */
  128. void *phy_data; /* private PHY date */
  129. unsigned long flags; /* device flags (ATM_DF_*) */
  130. struct list_head local; /* local ATM addresses */
  131. struct list_head lecs; /* LECS ATM addresses learned via ILMI */
  132. unsigned char esi[ESI_LEN]; /* ESI ("MAC" addr) */
  133. struct atm_cirange ci_range; /* VPI/VCI range */
  134. struct k_atm_dev_stats stats; /* statistics */
  135. char signal; /* signal status (ATM_PHY_SIG_*) */
  136. int link_rate; /* link rate (default: OC3) */
  137. atomic_t refcnt; /* reference count */
  138. spinlock_t lock; /* protect internal members */
  139. #ifdef CONFIG_PROC_FS
  140. struct proc_dir_entry *proc_entry; /* proc entry */
  141. char *proc_name; /* proc entry name */
  142. #endif
  143. struct device class_dev; /* sysfs device */
  144. struct list_head dev_list; /* linkage */
  145. };
  146. /* OF: send_Oam Flags */
  147. #define ATM_OF_IMMED 1 /* Attempt immediate delivery */
  148. #define ATM_OF_INRATE 2 /* Attempt in-rate delivery */
  149. /*
  150. * ioctl, getsockopt, and setsockopt are optional and can be set to NULL.
  151. */
  152. struct atmdev_ops { /* only send is required */
  153. void (*dev_close)(struct atm_dev *dev);
  154. int (*open)(struct atm_vcc *vcc);
  155. void (*close)(struct atm_vcc *vcc);
  156. int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
  157. #ifdef CONFIG_COMPAT
  158. int (*compat_ioctl)(struct atm_dev *dev,unsigned int cmd,
  159. void __user *arg);
  160. #endif
  161. int (*getsockopt)(struct atm_vcc *vcc,int level,int optname,
  162. void __user *optval,int optlen);
  163. int (*setsockopt)(struct atm_vcc *vcc,int level,int optname,
  164. void __user *optval,unsigned int optlen);
  165. int (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
  166. int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
  167. void (*phy_put)(struct atm_dev *dev,unsigned char value,
  168. unsigned long addr);
  169. unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
  170. int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
  171. int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
  172. struct module *owner;
  173. };
  174. struct atmphy_ops {
  175. int (*start)(struct atm_dev *dev);
  176. int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
  177. void (*interrupt)(struct atm_dev *dev);
  178. int (*stop)(struct atm_dev *dev);
  179. };
  180. struct atm_skb_data {
  181. struct atm_vcc *vcc; /* ATM VCC */
  182. unsigned long atm_options; /* ATM layer options */
  183. };
  184. #define VCC_HTABLE_SIZE 32
  185. extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
  186. extern rwlock_t vcc_sklist_lock;
  187. #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
  188. struct atm_dev *atm_dev_register(const char *type, struct device *parent,
  189. const struct atmdev_ops *ops,
  190. int number, /* -1 == pick first available */
  191. unsigned long *flags);
  192. struct atm_dev *atm_dev_lookup(int number);
  193. void atm_dev_deregister(struct atm_dev *dev);
  194. /* atm_dev_signal_change
  195. *
  196. * Propagate lower layer signal change in atm_dev->signal to netdevice.
  197. * The event will be sent via a notifier call chain.
  198. */
  199. void atm_dev_signal_change(struct atm_dev *dev, char signal);
  200. void vcc_insert_socket(struct sock *sk);
  201. void atm_dev_release_vccs(struct atm_dev *dev);
  202. static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
  203. {
  204. atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
  205. }
  206. static inline void atm_return(struct atm_vcc *vcc,int truesize)
  207. {
  208. atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
  209. }
  210. static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
  211. {
  212. return (size + atomic_read(&sk_atm(vcc)->sk_wmem_alloc)) <
  213. sk_atm(vcc)->sk_sndbuf;
  214. }
  215. static inline void atm_dev_hold(struct atm_dev *dev)
  216. {
  217. atomic_inc(&dev->refcnt);
  218. }
  219. static inline void atm_dev_put(struct atm_dev *dev)
  220. {
  221. if (atomic_dec_and_test(&dev->refcnt)) {
  222. BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
  223. if (dev->ops->dev_close)
  224. dev->ops->dev_close(dev);
  225. put_device(&dev->class_dev);
  226. }
  227. }
  228. int atm_charge(struct atm_vcc *vcc,int truesize);
  229. struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
  230. gfp_t gfp_flags);
  231. int atm_pcr_goal(const struct atm_trafprm *tp);
  232. void vcc_release_async(struct atm_vcc *vcc, int reply);
  233. struct atm_ioctl {
  234. struct module *owner;
  235. /* A module reference is kept if appropriate over this call.
  236. * Return -ENOIOCTLCMD if you don't handle it. */
  237. int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
  238. struct list_head list;
  239. };
  240. /**
  241. * register_atm_ioctl - register handler for ioctl operations
  242. *
  243. * Special (non-device) handlers of ioctl's should
  244. * register here. If you're a normal device, you should
  245. * set .ioctl in your atmdev_ops instead.
  246. */
  247. void register_atm_ioctl(struct atm_ioctl *);
  248. /**
  249. * deregister_atm_ioctl - remove the ioctl handler
  250. */
  251. void deregister_atm_ioctl(struct atm_ioctl *);
  252. /* register_atmdevice_notifier - register atm_dev notify events
  253. *
  254. * Clients like br2684 will register notify events
  255. * Currently we notify of signal found/lost
  256. */
  257. int register_atmdevice_notifier(struct notifier_block *nb);
  258. void unregister_atmdevice_notifier(struct notifier_block *nb);
  259. #endif