atmdev.h 10 KB

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