usbatm.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /******************************************************************************
  3. * usbatm.h - Generic USB xDSL driver core
  4. *
  5. * Copyright (C) 2001, Alcatel
  6. * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
  7. * Copyright (C) 2004, David Woodhouse
  8. ******************************************************************************/
  9. #ifndef _USBATM_H_
  10. #define _USBATM_H_
  11. #include <linux/atm.h>
  12. #include <linux/atmdev.h>
  13. #include <linux/completion.h>
  14. #include <linux/device.h>
  15. #include <linux/kernel.h>
  16. #include <linux/kref.h>
  17. #include <linux/list.h>
  18. #include <linux/stringify.h>
  19. #include <linux/usb.h>
  20. #include <linux/mutex.h>
  21. #include <linux/ratelimit.h>
  22. /*
  23. #define VERBOSE_DEBUG
  24. */
  25. #define usb_err(instance, format, arg...) \
  26. dev_err(&(instance)->usb_intf->dev , format , ## arg)
  27. #define usb_info(instance, format, arg...) \
  28. dev_info(&(instance)->usb_intf->dev , format , ## arg)
  29. #define usb_warn(instance, format, arg...) \
  30. dev_warn(&(instance)->usb_intf->dev , format , ## arg)
  31. #define usb_dbg(instance, format, arg...) \
  32. dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
  33. /* FIXME: move to dev_* once ATM is driver model aware */
  34. #define atm_printk(level, instance, format, arg...) \
  35. printk(level "ATM dev %d: " format , \
  36. (instance)->atm_dev->number , ## arg)
  37. #define atm_err(instance, format, arg...) \
  38. atm_printk(KERN_ERR, instance , format , ## arg)
  39. #define atm_info(instance, format, arg...) \
  40. atm_printk(KERN_INFO, instance , format , ## arg)
  41. #define atm_warn(instance, format, arg...) \
  42. atm_printk(KERN_WARNING, instance , format , ## arg)
  43. #define atm_dbg(instance, format, ...) \
  44. pr_debug("ATM dev %d: " format, \
  45. (instance)->atm_dev->number, ##__VA_ARGS__)
  46. #define atm_rldbg(instance, format, ...) \
  47. pr_debug_ratelimited("ATM dev %d: " format, \
  48. (instance)->atm_dev->number, ##__VA_ARGS__)
  49. /* flags, set by mini-driver in bind() */
  50. #define UDSL_SKIP_HEAVY_INIT (1<<0)
  51. #define UDSL_USE_ISOC (1<<1)
  52. #define UDSL_IGNORE_EILSEQ (1<<2)
  53. /* mini driver */
  54. struct usbatm_data;
  55. /*
  56. * Assuming all methods exist and succeed, they are called in this order:
  57. *
  58. * bind, heavy_init, atm_start, ..., atm_stop, unbind
  59. */
  60. struct usbatm_driver {
  61. const char *driver_name;
  62. /* init device ... can sleep, or cause probe() failure */
  63. int (*bind) (struct usbatm_data *, struct usb_interface *,
  64. const struct usb_device_id *id);
  65. /* additional device initialization that is too slow to be done in probe() */
  66. int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
  67. /* cleanup device ... can sleep, but can't fail */
  68. void (*unbind) (struct usbatm_data *, struct usb_interface *);
  69. /* init ATM device ... can sleep, or cause ATM initialization failure */
  70. int (*atm_start) (struct usbatm_data *, struct atm_dev *);
  71. /* cleanup ATM device ... can sleep, but can't fail */
  72. void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
  73. int bulk_in; /* bulk rx endpoint */
  74. int isoc_in; /* isochronous rx endpoint */
  75. int bulk_out; /* bulk tx endpoint */
  76. unsigned rx_padding;
  77. unsigned tx_padding;
  78. };
  79. extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
  80. struct usbatm_driver *driver);
  81. extern void usbatm_usb_disconnect(struct usb_interface *intf);
  82. struct usbatm_channel {
  83. int endpoint; /* usb pipe */
  84. unsigned int stride; /* ATM cell size + padding */
  85. unsigned int buf_size; /* urb buffer size */
  86. unsigned int packet_size; /* endpoint maxpacket */
  87. spinlock_t lock;
  88. struct list_head list;
  89. struct tasklet_struct tasklet;
  90. struct timer_list delay;
  91. struct usbatm_data *usbatm;
  92. };
  93. /* main driver data */
  94. struct usbatm_data {
  95. /******************
  96. * public fields *
  97. ******************/
  98. /* mini driver */
  99. struct usbatm_driver *driver;
  100. void *driver_data;
  101. char driver_name[16];
  102. unsigned int flags; /* set by mini-driver in bind() */
  103. /* USB device */
  104. struct usb_device *usb_dev;
  105. struct usb_interface *usb_intf;
  106. char description[64];
  107. /* ATM device */
  108. struct atm_dev *atm_dev;
  109. /********************************
  110. * private fields - do not use *
  111. ********************************/
  112. struct kref refcount;
  113. struct mutex serialize;
  114. int disconnected;
  115. /* heavy init */
  116. struct task_struct *thread;
  117. struct completion thread_started;
  118. struct completion thread_exited;
  119. /* ATM device */
  120. struct list_head vcc_list;
  121. struct usbatm_channel rx_channel;
  122. struct usbatm_channel tx_channel;
  123. struct sk_buff_head sndqueue;
  124. struct sk_buff *current_skb; /* being emptied */
  125. struct usbatm_vcc_data *cached_vcc;
  126. int cached_vci;
  127. short cached_vpi;
  128. unsigned char *cell_buf; /* holds partial rx cell */
  129. unsigned int buf_usage;
  130. struct urb *urbs[0];
  131. };
  132. static inline void *to_usbatm_driver_data(struct usb_interface *intf)
  133. {
  134. struct usbatm_data *usbatm_instance;
  135. if (intf == NULL)
  136. return NULL;
  137. usbatm_instance = usb_get_intfdata(intf);
  138. if (usbatm_instance == NULL) /* set NULL before unbind() */
  139. return NULL;
  140. return usbatm_instance->driver_data; /* set NULL after unbind() */
  141. }
  142. #endif /* _USBATM_H_ */