blob: 5fc489405217beb254398a3095fcd812faa36941 [file] [log] [blame]
Duncan Sandsc59bba72005-05-11 20:24:03 +02001/******************************************************************************
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
Duncan Sandsc59bba72005-05-11 20:24:03 +020027#include <linux/atm.h>
28#include <linux/atmdev.h>
29#include <linux/completion.h>
30#include <linux/device.h>
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010031#include <linux/kernel.h>
Duncan Sandsc59bba72005-05-11 20:24:03 +020032#include <linux/kref.h>
33#include <linux/list.h>
34#include <linux/stringify.h>
35#include <linux/usb.h>
Arjan van de Venab3c81f2006-01-13 15:52:55 +010036#include <linux/mutex.h>
Duncan Sandsc59bba72005-05-11 20:24:03 +020037
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010038/*
39#define VERBOSE_DEBUG
40*/
41
Duncan Sandsc59bba72005-05-11 20:24:03 +020042#ifdef DEBUG
Greg Kroah-Hartman3b6004f2008-08-14 09:37:34 -070043#define UDSL_ASSERT(instance, x) BUG_ON(!(x))
Duncan Sandsc59bba72005-05-11 20:24:03 +020044#else
Greg Kroah-Hartman3b6004f2008-08-14 09:37:34 -070045#define UDSL_ASSERT(instance, x) \
46 do { \
47 if (!(x)) \
48 dev_warn(&(instance)->usb_intf->dev, \
49 "failed assertion '%s' at line %d", \
50 __stringify(x), __LINE__); \
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020051 } while (0)
Duncan Sandsc59bba72005-05-11 20:24:03 +020052#endif
53
54#define usb_err(instance, format, arg...) \
55 dev_err(&(instance)->usb_intf->dev , format , ## arg)
56#define usb_info(instance, format, arg...) \
57 dev_info(&(instance)->usb_intf->dev , format , ## arg)
58#define usb_warn(instance, format, arg...) \
59 dev_warn(&(instance)->usb_intf->dev , format , ## arg)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010060#ifdef DEBUG
Duncan Sandsc59bba72005-05-11 20:24:03 +020061#define usb_dbg(instance, format, arg...) \
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020062 dev_printk(KERN_DEBUG , &(instance)->usb_intf->dev , format , ## arg)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010063#else
64#define usb_dbg(instance, format, arg...) \
65 do {} while (0)
66#endif
Duncan Sandsc59bba72005-05-11 20:24:03 +020067
68/* FIXME: move to dev_* once ATM is driver model aware */
69#define atm_printk(level, instance, format, arg...) \
Andrew Morton843c9442005-05-30 01:09:06 -070070 printk(level "ATM dev %d: " format , \
71 (instance)->atm_dev->number , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020072
73#define atm_err(instance, format, arg...) \
74 atm_printk(KERN_ERR, instance , format , ## arg)
75#define atm_info(instance, format, arg...) \
76 atm_printk(KERN_INFO, instance , format , ## arg)
77#define atm_warn(instance, format, arg...) \
78 atm_printk(KERN_WARNING, instance , format , ## arg)
79#ifdef DEBUG
80#define atm_dbg(instance, format, arg...) \
81 atm_printk(KERN_DEBUG, instance , format , ## arg)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010082#define atm_rldbg(instance, format, arg...) \
83 if (printk_ratelimit()) \
84 atm_printk(KERN_DEBUG, instance , format , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020085#else
86#define atm_dbg(instance, format, arg...) \
87 do {} while (0)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010088#define atm_rldbg(instance, format, arg...) \
89 do {} while (0)
Duncan Sandsc59bba72005-05-11 20:24:03 +020090#endif
91
92
Duncan Sands35644b02006-01-17 11:16:13 +010093/* flags, set by mini-driver in bind() */
94
95#define UDSL_SKIP_HEAVY_INIT (1<<0)
Duncan Sands80aae7a2006-01-13 10:59:23 +010096#define UDSL_USE_ISOC (1<<1)
Duncan Sandsa3673d32006-01-13 11:12:58 +010097#define UDSL_IGNORE_EILSEQ (1<<2)
Duncan Sands35644b02006-01-17 11:16:13 +010098
99
Duncan Sandsc59bba72005-05-11 20:24:03 +0200100/* mini driver */
101
102struct usbatm_data;
103
104/*
105* Assuming all methods exist and succeed, they are called in this order:
106*
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200107* bind, heavy_init, atm_start, ..., atm_stop, unbind
Duncan Sandsc59bba72005-05-11 20:24:03 +0200108*/
109
110struct usbatm_driver {
Duncan Sandsc59bba72005-05-11 20:24:03 +0200111 const char *driver_name;
112
Duncan Sands35644b02006-01-17 11:16:13 +0100113 /* init device ... can sleep, or cause probe() failure */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200114 int (*bind) (struct usbatm_data *, struct usb_interface *,
Duncan Sands35644b02006-01-17 11:16:13 +0100115 const struct usb_device_id *id);
Duncan Sandsc59bba72005-05-11 20:24:03 +0200116
117 /* additional device initialization that is too slow to be done in probe() */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200118 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
Duncan Sandsc59bba72005-05-11 20:24:03 +0200119
120 /* cleanup device ... can sleep, but can't fail */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200121 void (*unbind) (struct usbatm_data *, struct usb_interface *);
Duncan Sandsc59bba72005-05-11 20:24:03 +0200122
123 /* init ATM device ... can sleep, or cause ATM initialization failure */
124 int (*atm_start) (struct usbatm_data *, struct atm_dev *);
125
126 /* cleanup ATM device ... can sleep, but can't fail */
127 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
128
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200129 int bulk_in; /* bulk rx endpoint */
130 int isoc_in; /* isochronous rx endpoint */
131 int bulk_out; /* bulk tx endpoint */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200132
133 unsigned rx_padding;
134 unsigned tx_padding;
135};
136
137extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
138 struct usbatm_driver *driver);
139extern void usbatm_usb_disconnect(struct usb_interface *intf);
140
141
142struct usbatm_channel {
143 int endpoint; /* usb pipe */
144 unsigned int stride; /* ATM cell size + padding */
145 unsigned int buf_size; /* urb buffer size */
Duncan Sands80aae7a2006-01-13 10:59:23 +0100146 unsigned int packet_size; /* endpoint maxpacket */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200147 spinlock_t lock;
148 struct list_head list;
149 struct tasklet_struct tasklet;
150 struct timer_list delay;
151 struct usbatm_data *usbatm;
152};
153
154/* main driver data */
155
156struct usbatm_data {
157 /******************
158 * public fields *
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200159 ******************/
Duncan Sandsc59bba72005-05-11 20:24:03 +0200160
161 /* mini driver */
162 struct usbatm_driver *driver;
163 void *driver_data;
164 char driver_name[16];
Duncan Sands35644b02006-01-17 11:16:13 +0100165 unsigned int flags; /* set by mini-driver in bind() */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200166
167 /* USB device */
168 struct usb_device *usb_dev;
169 struct usb_interface *usb_intf;
170 char description[64];
171
172 /* ATM device */
173 struct atm_dev *atm_dev;
174
175 /********************************
176 * private fields - do not use *
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200177 ********************************/
Duncan Sandsc59bba72005-05-11 20:24:03 +0200178
179 struct kref refcount;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100180 struct mutex serialize;
Duncan Sands0e42a622006-01-13 10:05:15 +0100181 int disconnected;
Duncan Sandsc59bba72005-05-11 20:24:03 +0200182
183 /* heavy init */
Pavel Emelyanovc4504a72008-02-11 15:26:09 +0300184 struct task_struct *thread;
Duncan Sandsc59bba72005-05-11 20:24:03 +0200185 struct completion thread_started;
186 struct completion thread_exited;
187
188 /* ATM device */
189 struct list_head vcc_list;
190
191 struct usbatm_channel rx_channel;
192 struct usbatm_channel tx_channel;
193
194 struct sk_buff_head sndqueue;
Duncan Sands0ec3c7e2006-01-17 11:15:13 +0100195 struct sk_buff *current_skb; /* being emptied */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200196
Duncan Sandse3fb2f62006-01-13 11:06:46 +0100197 struct usbatm_vcc_data *cached_vcc;
198 int cached_vci;
199 short cached_vpi;
200
201 unsigned char *cell_buf; /* holds partial rx cell */
202 unsigned int buf_usage;
203
Duncan Sandsc59bba72005-05-11 20:24:03 +0200204 struct urb *urbs[0];
205};
206
Simon Arlott9fc950d2009-11-21 15:33:51 +0000207static inline void *to_usbatm_driver_data(struct usb_interface *intf)
208{
209 struct usbatm_data *usbatm_instance;
210
211 if (intf == NULL)
212 return NULL;
213
214 usbatm_instance = usb_get_intfdata(intf);
215
216 if (usbatm_instance == NULL) /* set NULL before unbind() */
217 return NULL;
218
219 return usbatm_instance->driver_data; /* set NULL after unbind() */
220}
221
Duncan Sandsc59bba72005-05-11 20:24:03 +0200222#endif /* _USBATM_H_ */