atmdev.h 9.4 KB

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