]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/usb/atm/usbatm.h
[PATCH] USBATM: trivial modifications
[linux-2.6-omap-h63xx.git] / drivers / usb / atm / usbatm.h
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
24 #ifndef _USBATM_H_
25 #define _USBATM_H_
26
27 #include <asm/semaphore.h>
28 #include <linux/atm.h>
29 #include <linux/atmdev.h>
30 #include <linux/completion.h>
31 #include <linux/device.h>
32 #include <linux/kernel.h>
33 #include <linux/kref.h>
34 #include <linux/list.h>
35 #include <linux/stringify.h>
36 #include <linux/usb.h>
37
38 /*
39 #define VERBOSE_DEBUG
40 */
41
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
48 #define usb_err(instance, format, arg...)       \
49         dev_err(&(instance)->usb_intf->dev , format , ## arg)
50 #define usb_info(instance, format, arg...)      \
51         dev_info(&(instance)->usb_intf->dev , format , ## arg)
52 #define usb_warn(instance, format, arg...)      \
53         dev_warn(&(instance)->usb_intf->dev , format , ## arg)
54 #ifdef DEBUG
55 #define usb_dbg(instance, format, arg...)       \
56         dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
57 #else
58 #define usb_dbg(instance, format, arg...)       \
59         do {} while (0)
60 #endif
61
62 /* FIXME: move to dev_* once ATM is driver model aware */
63 #define atm_printk(level, instance, format, arg...)     \
64         printk(level "ATM dev %d: " format ,            \
65         (instance)->atm_dev->number , ## arg)
66
67 #define atm_err(instance, format, arg...)       \
68         atm_printk(KERN_ERR, instance , format , ## arg)
69 #define atm_info(instance, format, arg...)      \
70         atm_printk(KERN_INFO, instance , format , ## arg)
71 #define atm_warn(instance, format, arg...)      \
72         atm_printk(KERN_WARNING, instance , format , ## arg)
73 #ifdef DEBUG
74 #define atm_dbg(instance, format, arg...)       \
75         atm_printk(KERN_DEBUG, instance , format , ## arg)
76 #define atm_rldbg(instance, format, arg...)     \
77         if (printk_ratelimit())                         \
78                 atm_printk(KERN_DEBUG, instance , format , ## arg)
79 #else
80 #define atm_dbg(instance, format, arg...)       \
81         do {} while (0)
82 #define atm_rldbg(instance, format, arg...)     \
83         do {} while (0)
84 #endif
85
86
87 /* mini driver */
88
89 struct usbatm_data;
90
91 /*
92 *  Assuming all methods exist and succeed, they are called in this order:
93 *
94 *       bind, heavy_init, atm_start, ..., atm_stop, unbind
95 */
96
97 struct usbatm_driver {
98         struct module *owner;
99
100         const char *driver_name;
101
102         /*
103         *  init device ... can sleep, or cause probe() failure.  Drivers with a heavy_init
104         *  method can avoid having it called by setting need_heavy_init to zero.
105         */
106         int (*bind) (struct usbatm_data *, struct usb_interface *,
107                      const struct usb_device_id *id, int *need_heavy_init);
108
109         /* additional device initialization that is too slow to be done in probe() */
110         int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
111
112         /* cleanup device ... can sleep, but can't fail */
113         void (*unbind) (struct usbatm_data *, struct usb_interface *);
114
115         /* init ATM device ... can sleep, or cause ATM initialization failure */
116         int (*atm_start) (struct usbatm_data *, struct atm_dev *);
117
118         /* cleanup ATM device ... can sleep, but can't fail */
119         void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
120
121         int in;         /* rx endpoint */
122         int out;        /* tx endpoint */
123
124         unsigned rx_padding;
125         unsigned tx_padding;
126 };
127
128 extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
129                 struct usbatm_driver *driver);
130 extern void usbatm_usb_disconnect(struct usb_interface *intf);
131
132
133 struct usbatm_channel {
134         int endpoint;                   /* usb pipe */
135         unsigned int stride;            /* ATM cell size + padding */
136         unsigned int buf_size;          /* urb buffer size */
137         spinlock_t lock;
138         struct list_head list;
139         struct tasklet_struct tasklet;
140         struct timer_list delay;
141         struct usbatm_data *usbatm;
142 };
143
144 /* main driver data */
145
146 struct usbatm_data {
147         /******************
148         *  public fields  *
149         ******************/
150
151         /* mini driver */
152         struct usbatm_driver *driver;
153         void *driver_data;
154         char driver_name[16];
155
156         /* USB device */
157         struct usb_device *usb_dev;
158         struct usb_interface *usb_intf;
159         char description[64];
160
161         /* ATM device */
162         struct atm_dev *atm_dev;
163
164         /********************************
165         *  private fields - do not use  *
166         ********************************/
167
168         struct kref refcount;
169         struct semaphore serialize;
170
171         /* heavy init */
172         int thread_pid;
173         struct completion thread_started;
174         struct completion thread_exited;
175
176         /* ATM device */
177         struct list_head vcc_list;
178
179         struct usbatm_channel rx_channel;
180         struct usbatm_channel tx_channel;
181
182         struct sk_buff_head sndqueue;
183         struct sk_buff *current_skb;    /* being emptied */
184
185         struct urb *urbs[0];
186 };
187
188 #endif  /* _USBATM_H_ */