atmdev.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. 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 (*send)(struct atm_vcc *vcc,struct sk_buff *skb);
  161. int (*send_oam)(struct atm_vcc *vcc,void *cell,int flags);
  162. void (*phy_put)(struct atm_dev *dev,unsigned char value,
  163. unsigned long addr);
  164. unsigned char (*phy_get)(struct atm_dev *dev,unsigned long addr);
  165. int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
  166. int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
  167. struct module *owner;
  168. };
  169. struct atmphy_ops {
  170. int (*start)(struct atm_dev *dev);
  171. int (*ioctl)(struct atm_dev *dev,unsigned int cmd,void __user *arg);
  172. void (*interrupt)(struct atm_dev *dev);
  173. int (*stop)(struct atm_dev *dev);
  174. };
  175. struct atm_skb_data {
  176. struct atm_vcc *vcc; /* ATM VCC */
  177. unsigned long atm_options; /* ATM layer options */
  178. unsigned int acct_truesize; /* truesize accounted to vcc */
  179. };
  180. #define VCC_HTABLE_SIZE 32
  181. extern struct hlist_head vcc_hash[VCC_HTABLE_SIZE];
  182. extern rwlock_t vcc_sklist_lock;
  183. #define ATM_SKB(skb) (((struct atm_skb_data *) (skb)->cb))
  184. struct atm_dev *atm_dev_register(const char *type, struct device *parent,
  185. const struct atmdev_ops *ops,
  186. int number, /* -1 == pick first available */
  187. unsigned long *flags);
  188. struct atm_dev *atm_dev_lookup(int number);
  189. void atm_dev_deregister(struct atm_dev *dev);
  190. /* atm_dev_signal_change
  191. *
  192. * Propagate lower layer signal change in atm_dev->signal to netdevice.
  193. * The event will be sent via a notifier call chain.
  194. */
  195. void atm_dev_signal_change(struct atm_dev *dev, char signal);
  196. void vcc_insert_socket(struct sock *sk);
  197. void atm_dev_release_vccs(struct atm_dev *dev);
  198. static inline void atm_account_tx(struct atm_vcc *vcc, struct sk_buff *skb)
  199. {
  200. /*
  201. * Because ATM skbs may not belong to a sock (and we don't
  202. * necessarily want to), skb->truesize may be adjusted,
  203. * escaping the hack in pskb_expand_head() which avoids
  204. * doing so for some cases. So stash the value of truesize
  205. * at the time we accounted it, and atm_pop_raw() can use
  206. * that value later, in case it changes.
  207. */
  208. refcount_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  209. ATM_SKB(skb)->acct_truesize = skb->truesize;
  210. ATM_SKB(skb)->atm_options = vcc->atm_options;
  211. }
  212. static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
  213. {
  214. atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
  215. }
  216. static inline void atm_return(struct atm_vcc *vcc,int truesize)
  217. {
  218. atomic_sub(truesize, &sk_atm(vcc)->sk_rmem_alloc);
  219. }
  220. static inline int atm_may_send(struct atm_vcc *vcc,unsigned int size)
  221. {
  222. return (size + refcount_read(&sk_atm(vcc)->sk_wmem_alloc)) <
  223. sk_atm(vcc)->sk_sndbuf;
  224. }
  225. static inline void atm_dev_hold(struct atm_dev *dev)
  226. {
  227. refcount_inc(&dev->refcnt);
  228. }
  229. static inline void atm_dev_put(struct atm_dev *dev)
  230. {
  231. if (refcount_dec_and_test(&dev->refcnt)) {
  232. BUG_ON(!test_bit(ATM_DF_REMOVED, &dev->flags));
  233. if (dev->ops->dev_close)
  234. dev->ops->dev_close(dev);
  235. put_device(&dev->class_dev);
  236. }
  237. }
  238. int atm_charge(struct atm_vcc *vcc,int truesize);
  239. struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc,int pdu_size,
  240. gfp_t gfp_flags);
  241. int atm_pcr_goal(const struct atm_trafprm *tp);
  242. void vcc_release_async(struct atm_vcc *vcc, int reply);
  243. struct atm_ioctl {
  244. struct module *owner;
  245. /* A module reference is kept if appropriate over this call.
  246. * Return -ENOIOCTLCMD if you don't handle it. */
  247. int (*ioctl)(struct socket *, unsigned int cmd, unsigned long arg);
  248. struct list_head list;
  249. };
  250. /**
  251. * register_atm_ioctl - register handler for ioctl operations
  252. *
  253. * Special (non-device) handlers of ioctl's should
  254. * register here. If you're a normal device, you should
  255. * set .ioctl in your atmdev_ops instead.
  256. */
  257. void register_atm_ioctl(struct atm_ioctl *);
  258. /**
  259. * deregister_atm_ioctl - remove the ioctl handler
  260. */
  261. void deregister_atm_ioctl(struct atm_ioctl *);
  262. /* register_atmdevice_notifier - register atm_dev notify events
  263. *
  264. * Clients like br2684 will register notify events
  265. * Currently we notify of signal found/lost
  266. */
  267. int register_atmdevice_notifier(struct notifier_block *nb);
  268. void unregister_atmdevice_notifier(struct notifier_block *nb);
  269. #endif