blob: 71dd13994bbe07dc1098e12b9416571e161ed0ed [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#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...) \
Greg Kroah-Hartmanca4d7012013-06-28 11:32:52 -070049 dev_dbg(&(instance)->usb_intf->dev , format , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020050
51/* FIXME: move to dev_* once ATM is driver model aware */
52#define atm_printk(level, instance, format, arg...) \
Andrew Morton843c9442005-05-30 01:09:06 -070053 printk(level "ATM dev %d: " format , \
54 (instance)->atm_dev->number , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020055
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)
62#ifdef DEBUG
63#define atm_dbg(instance, format, arg...) \
64 atm_printk(KERN_DEBUG, instance , format , ## arg)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010065#define atm_rldbg(instance, format, arg...) \
66 if (printk_ratelimit()) \
67 atm_printk(KERN_DEBUG, instance , format , ## arg)
Duncan Sandsc59bba72005-05-11 20:24:03 +020068#else
69#define atm_dbg(instance, format, arg...) \
70 do {} while (0)
Duncan Sands0ec3c7e2006-01-17 11:15:13 +010071#define atm_rldbg(instance, format, arg...) \
72 do {} while (0)
Duncan Sandsc59bba72005-05-11 20:24:03 +020073#endif
74
75
Duncan Sands35644b02006-01-17 11:16:13 +010076/* flags, set by mini-driver in bind() */
77
78#define UDSL_SKIP_HEAVY_INIT (1<<0)
Duncan Sands80aae7a2006-01-13 10:59:23 +010079#define UDSL_USE_ISOC (1<<1)
Duncan Sandsa3673d32006-01-13 11:12:58 +010080#define UDSL_IGNORE_EILSEQ (1<<2)
Duncan Sands35644b02006-01-17 11:16:13 +010081
82
Duncan Sandsc59bba72005-05-11 20:24:03 +020083/* mini driver */
84
85struct usbatm_data;
86
87/*
88* Assuming all methods exist and succeed, they are called in this order:
89*
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020090* bind, heavy_init, atm_start, ..., atm_stop, unbind
Duncan Sandsc59bba72005-05-11 20:24:03 +020091*/
92
93struct usbatm_driver {
Duncan Sandsc59bba72005-05-11 20:24:03 +020094 const char *driver_name;
95
Duncan Sands35644b02006-01-17 11:16:13 +010096 /* init device ... can sleep, or cause probe() failure */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +020097 int (*bind) (struct usbatm_data *, struct usb_interface *,
Duncan Sands35644b02006-01-17 11:16:13 +010098 const struct usb_device_id *id);
Duncan Sandsc59bba72005-05-11 20:24:03 +020099
100 /* additional device initialization that is too slow to be done in probe() */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200101 int (*heavy_init) (struct usbatm_data *, struct usb_interface *);
Duncan Sandsc59bba72005-05-11 20:24:03 +0200102
103 /* cleanup device ... can sleep, but can't fail */
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200104 void (*unbind) (struct usbatm_data *, struct usb_interface *);
Duncan Sandsc59bba72005-05-11 20:24:03 +0200105
106 /* init ATM device ... can sleep, or cause ATM initialization failure */
107 int (*atm_start) (struct usbatm_data *, struct atm_dev *);
108
109 /* cleanup ATM device ... can sleep, but can't fail */
110 void (*atm_stop) (struct usbatm_data *, struct atm_dev *);
111
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200112 int bulk_in; /* bulk rx endpoint */
113 int isoc_in; /* isochronous rx endpoint */
114 int bulk_out; /* bulk tx endpoint */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200115
116 unsigned rx_padding;
117 unsigned tx_padding;
118};
119
120extern int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
121 struct usbatm_driver *driver);
122extern void usbatm_usb_disconnect(struct usb_interface *intf);
123
124
125struct usbatm_channel {
126 int endpoint; /* usb pipe */
127 unsigned int stride; /* ATM cell size + padding */
128 unsigned int buf_size; /* urb buffer size */
Duncan Sands80aae7a2006-01-13 10:59:23 +0100129 unsigned int packet_size; /* endpoint maxpacket */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200130 spinlock_t lock;
131 struct list_head list;
132 struct tasklet_struct tasklet;
133 struct timer_list delay;
134 struct usbatm_data *usbatm;
135};
136
137/* main driver data */
138
139struct usbatm_data {
140 /******************
141 * public fields *
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200142 ******************/
Duncan Sandsc59bba72005-05-11 20:24:03 +0200143
144 /* mini driver */
145 struct usbatm_driver *driver;
146 void *driver_data;
147 char driver_name[16];
Duncan Sands35644b02006-01-17 11:16:13 +0100148 unsigned int flags; /* set by mini-driver in bind() */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200149
150 /* USB device */
151 struct usb_device *usb_dev;
152 struct usb_interface *usb_intf;
153 char description[64];
154
155 /* ATM device */
156 struct atm_dev *atm_dev;
157
158 /********************************
159 * private fields - do not use *
Nicolas Kaiser16f76a72010-06-17 11:55:49 +0200160 ********************************/
Duncan Sandsc59bba72005-05-11 20:24:03 +0200161
162 struct kref refcount;
Arjan van de Venab3c81f2006-01-13 15:52:55 +0100163 struct mutex serialize;
Duncan Sands0e42a622006-01-13 10:05:15 +0100164 int disconnected;
Duncan Sandsc59bba72005-05-11 20:24:03 +0200165
166 /* heavy init */
Pavel Emelyanovc4504a72008-02-11 15:26:09 +0300167 struct task_struct *thread;
Duncan Sandsc59bba72005-05-11 20:24:03 +0200168 struct completion thread_started;
169 struct completion thread_exited;
170
171 /* ATM device */
172 struct list_head vcc_list;
173
174 struct usbatm_channel rx_channel;
175 struct usbatm_channel tx_channel;
176
177 struct sk_buff_head sndqueue;
Duncan Sands0ec3c7e2006-01-17 11:15:13 +0100178 struct sk_buff *current_skb; /* being emptied */
Duncan Sandsc59bba72005-05-11 20:24:03 +0200179
Duncan Sandse3fb2f62006-01-13 11:06:46 +0100180 struct usbatm_vcc_data *cached_vcc;
181 int cached_vci;
182 short cached_vpi;
183
184 unsigned char *cell_buf; /* holds partial rx cell */
185 unsigned int buf_usage;
186
Duncan Sandsc59bba72005-05-11 20:24:03 +0200187 struct urb *urbs[0];
188};
189
Simon Arlott9fc950d2009-11-21 15:33:51 +0000190static inline void *to_usbatm_driver_data(struct usb_interface *intf)
191{
192 struct usbatm_data *usbatm_instance;
193
194 if (intf == NULL)
195 return NULL;
196
197 usbatm_instance = usb_get_intfdata(intf);
198
199 if (usbatm_instance == NULL) /* set NULL before unbind() */
200 return NULL;
201
202 return usbatm_instance->driver_data; /* set NULL after unbind() */
203}
204
Duncan Sandsc59bba72005-05-11 20:24:03 +0200205#endif /* _USBATM_H_ */