usbatm.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /******************************************************************************
  2. * usbatm.h - Generic USB xDSL driver core
  3. *
  4. * Copyright (C) 2001, Alcatel
  5. * Copyright (C) 2003, Duncan Sands, SolNegro, Josep Comas
  6. * Copyright (C) 2004, David Woodhouse
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc., 59
  20. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. *
  22. ******************************************************************************/
  23. #ifndef _USBATM_H_
  24. #define _USBATM_H_
  25. #include <linux/config.h>
  26. /*
  27. #define DEBUG
  28. #define VERBOSE_DEBUG
  29. */
  30. #if !defined (DEBUG) && defined (CONFIG_USB_DEBUG)
  31. # define DEBUG
  32. #endif
  33. #include <asm/semaphore.h>
  34. #include <linux/atm.h>
  35. #include <linux/atmdev.h>
  36. #include <linux/completion.h>
  37. #include <linux/device.h>
  38. #include <linux/kref.h>
  39. #include <linux/list.h>
  40. #include <linux/stringify.h>
  41. #include <linux/usb.h>
  42. #ifdef DEBUG
  43. #define UDSL_ASSERT(x) BUG_ON(!(x))
  44. #else
  45. #define UDSL_ASSERT(x) do { if (!(x)) warn("failed assertion '%s' at line %d", __stringify(x), __LINE__); } while(0)
  46. #endif
  47. #define usb_err(instance, format, arg...) \
  48. dev_err(&(instance)->usb_intf->dev , format , ## arg)
  49. #define usb_info(instance, format, arg...) \
  50. dev_info(&(instance)->usb_intf->dev , format , ## arg)
  51. #define usb_warn(instance, format, arg...) \
  52. dev_warn(&(instance)->usb_intf->dev , format , ## arg)
  53. #define usb_dbg(instance, format, arg...) \
  54. dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
  55. /* FIXME: move to dev_* once ATM is driver model aware */
  56. #define atm_printk(level, instance, format, arg...) \
  57. printk(level "ATM dev %d: " format , \
  58. (instance)->atm_dev->number , ## arg)
  59. #define atm_err(instance, format, arg...) \
  60. atm_printk(KERN_ERR, instance , format , ## arg)
  61. #define atm_info(instance, format, arg...) \
  62. atm_printk(KERN_INFO, instance , format , ## arg)
  63. #define atm_warn(instance, format, arg...) \
  64. atm_printk(KERN_WARNING, instance , format , ## arg)
  65. #ifdef DEBUG
  66. #define atm_dbg(instance, format, arg...) \
  67. atm_printk(KERN_DEBUG, instance , format , ## arg)
  68. #else
  69. #define atm_dbg(instance, format, arg...) \
  70. do {} while (0)
  71. #endif
  72. /* mini driver */
  73. struct usbatm_data;
  74. /*
  75. * Assuming all methods exist and succeed, they are called in this order:
  76. *
  77. * bind, heavy_init, atm_start, ..., atm_stop, unbind
  78. */
  79. struct usbatm_driver {
  80. struct module *owner;
  81. const char *driver_name;
  82. /*
  83. * init device ... can sleep, or cause probe() failure. Drivers with a heavy_init
  84. * method can avoid having it called by setting need_heavy_init to zero.
  85. */
  86. int (*bind) (struct usbatm_data *, struct usb_interface *,
  87. const struct usb_device_id *id, int *need_heavy_init);
  88. /* additional device initialization that is too slow to be done in probe() */
  89. int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
  90. /* cleanup device ... can sleep, but can't fail */
  91. void (*unbind) (struct usbatm_data *, struct usb_interface *);
  92. /* init ATM device ... can sleep, or cause ATM initialization failure */
  93. int (*atm_start) (struct usbatm_data *, struct atm_dev *);
  94. /* cleanup ATM device ... can sleep, but can't fail */
  95. void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
  96. int in; /* rx endpoint */
  97. int out; /* tx endpoint */
  98. unsigned rx_padding;
  99. unsigned tx_padding;
  100. };
  101. extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
  102. struct usbatm_driver *driver);
  103. extern void usbatm_usb_disconnect(struct usb_interface *intf);
  104. struct usbatm_channel {
  105. int endpoint; /* usb pipe */
  106. unsigned int stride; /* ATM cell size + padding */
  107. unsigned int buf_size; /* urb buffer size */
  108. spinlock_t lock;
  109. struct list_head list;
  110. struct tasklet_struct tasklet;
  111. struct timer_list delay;
  112. struct usbatm_data *usbatm;
  113. };
  114. /* main driver data */
  115. struct usbatm_data {
  116. /******************
  117. * public fields *
  118. ******************/
  119. /* mini driver */
  120. struct usbatm_driver *driver;
  121. void *driver_data;
  122. char driver_name[16];
  123. /* USB device */
  124. struct usb_device *usb_dev;
  125. struct usb_interface *usb_intf;
  126. char description[64];
  127. /* ATM device */
  128. struct atm_dev *atm_dev;
  129. /********************************
  130. * private fields - do not use *
  131. ********************************/
  132. struct kref refcount;
  133. struct semaphore serialize;
  134. /* heavy init */
  135. int thread_pid;
  136. struct completion thread_started;
  137. struct completion thread_exited;
  138. /* ATM device */
  139. struct list_head vcc_list;
  140. struct usbatm_channel rx_channel;
  141. struct usbatm_channel tx_channel;
  142. struct sk_buff_head sndqueue;
  143. struct sk_buff *current_skb; /* being emptied */
  144. struct urb *urbs[0];
  145. };
  146. #endif /* _USBATM_H_ */