Commit | Line | Data |
---|---|---|
c59bba75 DS |
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 | ||
c59bba75 DS |
27 | #include <linux/atm.h> |
28 | #include <linux/atmdev.h> | |
29 | #include <linux/completion.h> | |
30 | #include <linux/device.h> | |
0ec3c7e8 | 31 | #include <linux/kernel.h> |
c59bba75 DS |
32 | #include <linux/kref.h> |
33 | #include <linux/list.h> | |
34 | #include <linux/stringify.h> | |
35 | #include <linux/usb.h> | |
ab3c81ff | 36 | #include <linux/mutex.h> |
c59bba75 | 37 | |
0ec3c7e8 DS |
38 | /* |
39 | #define VERBOSE_DEBUG | |
40 | */ | |
41 | ||
c59bba75 DS |
42 | #define usb_err(instance, format, arg...) \ |
43 | dev_err(&(instance)->usb_intf->dev , format , ## arg) | |
44 | #define usb_info(instance, format, arg...) \ | |
45 | dev_info(&(instance)->usb_intf->dev , format , ## arg) | |
46 | #define usb_warn(instance, format, arg...) \ | |
47 | dev_warn(&(instance)->usb_intf->dev , format , ## arg) | |
48 | #define usb_dbg(instance, format, arg...) \ | |
ca4d7013 | 49 | dev_dbg(&(instance)->usb_intf->dev , format , ## arg) |
c59bba75 DS |
50 | |
51 | /* FIXME: move to dev_* once ATM is driver model aware */ | |
52 | #define atm_printk(level, instance, format, arg...) \ | |
843c944f AM |
53 | printk(level "ATM dev %d: " format , \ |
54 | (instance)->atm_dev->number , ## arg) | |
c59bba75 DS |
55 | |
56 | #define atm_err(instance, format, arg...) \ | |
57 | atm_printk(KERN_ERR, instance , format , ## arg) | |
58 | #define atm_info(instance, format, arg...) \ | |
59 | atm_printk(KERN_INFO, instance , format , ## arg) | |
60 | #define atm_warn(instance, format, arg...) \ | |
61 | atm_printk(KERN_WARNING, instance , format , ## arg) | |
2d6401cf GKH |
62 | #define atm_dbg(instance, format, arg...) \ |
63 | dynamic_pr_debug("ATM dev %d: " format , \ | |
64 | (instance)->atm_dev->number , ## arg) | |
65 | #define atm_rldbg(instance, format, arg...) \ | |
0ec3c7e8 | 66 | if (printk_ratelimit()) \ |
2d6401cf | 67 | atm_dbg(instance , format , ## arg) |
c59bba75 DS |
68 | |
69 | ||
35644b0c DS |
70 | /* flags, set by mini-driver in bind() */ |
71 | ||
72 | #define UDSL_SKIP_HEAVY_INIT (1<<0) | |
80aae7a1 | 73 | #define UDSL_USE_ISOC (1<<1) |
a3673d3c | 74 | #define UDSL_IGNORE_EILSEQ (1<<2) |
35644b0c DS |
75 | |
76 | ||
c59bba75 DS |
77 | /* mini driver */ |
78 | ||
79 | struct usbatm_data; | |
80 | ||
81 | /* | |
82 | * Assuming all methods exist and succeed, they are called in this order: | |
83 | * | |
16f76a76 | 84 | * bind, heavy_init, atm_start, ..., atm_stop, unbind |
c59bba75 DS |
85 | */ |
86 | ||
87 | struct usbatm_driver { | |
c59bba75 DS |
88 | const char *driver_name; |
89 | ||
35644b0c | 90 | /* init device ... can sleep, or cause probe() failure */ |
16f76a76 | 91 | int (*bind) (struct usbatm_data *, struct usb_interface *, |
35644b0c | 92 | const struct usb_device_id *id); |
c59bba75 DS |
93 | |
94 | /* additional device initialization that is too slow to be done in probe() */ | |
16f76a76 | 95 | int (*heavy_init) (struct usbatm_data *, struct usb_interface *); |
c59bba75 DS |
96 | |
97 | /* cleanup device ... can sleep, but can't fail */ | |
16f76a76 | 98 | void (*unbind) (struct usbatm_data *, struct usb_interface *); |
c59bba75 DS |
99 | |
100 | /* init ATM device ... can sleep, or cause ATM initialization failure */ | |
101 | int (*atm_start) (struct usbatm_data *, struct atm_dev *); | |
102 | ||
103 | /* cleanup ATM device ... can sleep, but can't fail */ | |
104 | void (*atm_stop) (struct usbatm_data *, struct atm_dev *); | |
105 | ||
16f76a76 NK |
106 | int bulk_in; /* bulk rx endpoint */ |
107 | int isoc_in; /* isochronous rx endpoint */ | |
108 | int bulk_out; /* bulk tx endpoint */ | |
c59bba75 DS |
109 | |
110 | unsigned rx_padding; | |
111 | unsigned tx_padding; | |
112 | }; | |
113 | ||
114 | extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id, | |
115 | struct usbatm_driver *driver); | |
116 | extern void usbatm_usb_disconnect(struct usb_interface *intf); | |
117 | ||
118 | ||
119 | struct usbatm_channel { | |
120 | int endpoint; /* usb pipe */ | |
121 | unsigned int stride; /* ATM cell size + padding */ | |
122 | unsigned int buf_size; /* urb buffer size */ | |
80aae7a1 | 123 | unsigned int packet_size; /* endpoint maxpacket */ |
c59bba75 DS |
124 | spinlock_t lock; |
125 | struct list_head list; | |
126 | struct tasklet_struct tasklet; | |
127 | struct timer_list delay; | |
128 | struct usbatm_data *usbatm; | |
129 | }; | |
130 | ||
131 | /* main driver data */ | |
132 | ||
133 | struct usbatm_data { | |
134 | /****************** | |
135 | * public fields * | |
16f76a76 | 136 | ******************/ |
c59bba75 DS |
137 | |
138 | /* mini driver */ | |
139 | struct usbatm_driver *driver; | |
140 | void *driver_data; | |
141 | char driver_name[16]; | |
35644b0c | 142 | unsigned int flags; /* set by mini-driver in bind() */ |
c59bba75 DS |
143 | |
144 | /* USB device */ | |
145 | struct usb_device *usb_dev; | |
146 | struct usb_interface *usb_intf; | |
147 | char description[64]; | |
148 | ||
149 | /* ATM device */ | |
150 | struct atm_dev *atm_dev; | |
151 | ||
152 | /******************************** | |
153 | * private fields - do not use * | |
16f76a76 | 154 | ********************************/ |
c59bba75 DS |
155 | |
156 | struct kref refcount; | |
ab3c81ff | 157 | struct mutex serialize; |
0e42a627 | 158 | int disconnected; |
c59bba75 DS |
159 | |
160 | /* heavy init */ | |
c4504a7e | 161 | struct task_struct *thread; |
c59bba75 DS |
162 | struct completion thread_started; |
163 | struct completion thread_exited; | |
164 | ||
165 | /* ATM device */ | |
166 | struct list_head vcc_list; | |
167 | ||
168 | struct usbatm_channel rx_channel; | |
169 | struct usbatm_channel tx_channel; | |
170 | ||
171 | struct sk_buff_head sndqueue; | |
0ec3c7e8 | 172 | struct sk_buff *current_skb; /* being emptied */ |
c59bba75 | 173 | |
e3fb2f64 DS |
174 | struct usbatm_vcc_data *cached_vcc; |
175 | int cached_vci; | |
176 | short cached_vpi; | |
177 | ||
178 | unsigned char *cell_buf; /* holds partial rx cell */ | |
179 | unsigned int buf_usage; | |
180 | ||
c59bba75 DS |
181 | struct urb *urbs[0]; |
182 | }; | |
183 | ||
9fc950d3 SA |
184 | static inline void *to_usbatm_driver_data(struct usb_interface *intf) |
185 | { | |
186 | struct usbatm_data *usbatm_instance; | |
187 | ||
188 | if (intf == NULL) | |
189 | return NULL; | |
190 | ||
191 | usbatm_instance = usb_get_intfdata(intf); | |
192 | ||
193 | if (usbatm_instance == NULL) /* set NULL before unbind() */ | |
194 | return NULL; | |
195 | ||
196 | return usbatm_instance->driver_data; /* set NULL after unbind() */ | |
197 | } | |
198 | ||
c59bba75 | 199 | #endif /* _USBATM_H_ */ |